简体   繁体   English

玉缩进错误

[英]Jade indentation errors

So for my Express site, I'm using jade. 所以对于我的Express网站,我正在使用玉。 So I decided to try modifying my layout file so I can start designing my site. 所以我决定尝试修改我的布局文件,以便开始设计我的网站。 I modified the original layout code (which worked), but I started getting indentation errors in any file that extends layout like this: 我修改了原始布局代码(有效),但我开始在任何扩展布局的文件中得到缩进错误,如下所示:

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)

So the code that I have is this: 所以我的代码是这样的:

index.jade index.jade

extends layout

block content
    p Hello World

and

doctype 5
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')

    body
        div#header
            p This is the header
        block content

Keep in mind that I didn't spell anything incorrectly, and I do know how to link together files using the extends option just fine. 请记住,我没有拼写错误,我知道如何使用extends选项将文件链接在一起就好了。 In fact, the code worked perfectly fine until I started messing with the layout file. 事实上,代码工作得很好,直到我开始搞乱布局文件。 All of this is mostly an indention issue. 所有这些主要是一个缩进问题。 I tried figuring out if it is my text editor causing the problem, and I have been unsuccessful figuring out if it is, as I can't get the code working again. 我试着搞清楚它是否是我的文本编辑器导致问题,而且我一直没有成功搞清楚它是否是,因为我无法让代码再次运行。

I am using the sublime text 2 editor to write this jade code. 我正在使用sublime text 2编辑器来编写这个jade代码。 If it is the text editor not indenting correctly, could somebody help me learn how to fix it? 如果文本编辑器没有正确缩进,有人可以帮我学习如何解决它吗?

In the lower right-hand corner of Sublime Text, there should be a label that says Spaces: N or Tab Size: N where N is a number. 在Sublime Text的右下角,应该有一个标签,上面写着Spaces: NTab Size: N ,其中N是一个数字。 Select this and you'll see options to convert the entire document's indentation to use either tabs or spaces: 选择此选项,您将看到将整个文档的缩进转换为使用制表符或空格的选项:

  • Convert Indentation to Spaces
  • Convert Indentation to Tabs

for edit form on server.js file set variable like this 对于server.js上的编辑表单,设置这样的变量

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

for edit.jade file : 对于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

This answer is an extension to the answer of André Dion (I don't have enough reputation to comment on his post). 这个答案是AndréDion答案的延伸(我没有足够的声誉评论他的帖子)。 One can also do the same procedure he described in Visual Studio Code Directly. 也可以执行他在Visual Studio Code Directly中描述的相同过程。 If you use Pug in Visual Studio Code it will be very nice. 如果您在Visual Studio Code中使用Pug,那将非常好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM