Jade压痕错误

Jade indentation errors

本文关键字:错误 Jade      更新时间:2023-09-26

所以对于我的Express站点,我使用的是jade。所以我决定尝试修改我的布局文件,这样我就可以开始设计我的网站了。我修改了原始布局代码(有效),但我开始在任何扩展布局的文件中出现缩进错误,如下所示:

500 Error: /home/kevin/Blue/views/layout.jade:6 4| p Hello World Invalid indentation, you can use tabs or spaces but not both
4| p Hello World
Invalid indentation, you can use tabs or spaces but not both
at Object.Lexer.indent (/home/kevin/Blue/node_modules/jade/lib/lexer.js:679:15)
at Object.Lexer.next (/home/kevin/Blue/node_modules/jade/lib/lexer.js:777:15)
at Object.Lexer.lookahead (/home/kevin/Blue/node_modules/jade/lib/lexer.js:107:46)
at Object.Parser.lookahead (/home/kevin/Blue/node_modules/jade/lib/parser.js:115:23)
at Object.Parser.peek (/home/kevin/Blue/node_modules/jade/lib/parser.js:92:17)
at Object.Parser.tag (/home/kevin/Blue/node_modules/jade/lib/parser.js:640:22)
at Object.Parser.parseTag (/home/kevin/Blue/node_modules/jade/lib/parser.js:624:17)
at Object.Parser.parseExpr (/home/kevin/Blue/node_modules/jade/lib/parser.js:198:21)
at Object.Parser.block (/home/kevin/Blue/node_modules/jade/lib/parser.js:592:25)
at Object.Parser.tag (/home/kevin/Blue/node_modules/jade/lib/parser.js:721:26)

所以我的代码是:

index.jade

extends layout
block content
    p Hello World

doctype 5
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    body
        div#header
            p This is the header
        block content

请记住,我没有拼写错误,而且我知道如何使用扩展选项将文件链接在一起。事实上,在我开始扰乱布局文件之前,代码运行得非常好。所有这些主要是一个缩进问题。我试着弄清楚是否是我的文本编辑器造成了问题,但我一直没能弄清楚是不是,因为我无法让代码重新工作。

我正在用崇高的文本2编辑器来写这个玉代码。如果是文本编辑器缩进不正确,有人能帮我学习如何修复吗?

在Sublime Text的右下角,应该有一个标签,上面写着Spaces: NTab Size: N,其中N是一个数字。选择此选项,您将看到将整个文档的缩进转换为使用制表符或空格的选项:

  • Convert Indentation to Spaces
  • Convert Indentation to Tabs

用于server.js上的编辑表单文件集变量,如

var applications = row;
res.render("edit", { applications : applications[0] }); 

对于edit.jade文件:

block content
table
    thead
      tr
        th First Name
        th Last Name
    tbody
      - each item in applications
        tr
          td= item.username
          td= item.email

这个答案是AndréDion答案的扩展(我没有足够的声誉来评论他的帖子)。也可以直接执行他在Visual Studio代码中描述的相同过程。如果您在Visual Studio代码中使用Pug,那将是非常好的。