Jade - missing space before text for line x of jade file

后端 未结 6 1988
一整个雨季
一整个雨季 2020-12-30 19:05

I\'m making an Express based web application and everytime someone visits this jade file i get the following error:

Warning: missing space before text for li         


        
相关标签:
6条回答
  • 2020-12-30 19:44

    this may also be caused by using tabs instead of spaces

    div(attr="val")[\t]text
    

    or by \t characters at the ends of lines

    0 讨论(0)
  • 2020-12-30 19:46

    In Jade use | when start with only text

    wrong ->

    td
      {{anything}}
      br
      Hello
    

    correct ->

    td
      | {{anything}}
      br
      | Hello
    
    0 讨论(0)
  • 2020-12-30 19:49

    I took your code and copied into Notepad++ with View Whitespace on.

    Line 28 has 4 extra spaces at the end of it (shown as dashes here):

    input(style="width:75px;height:30px;", type="submit", value="Login")----
    

    Also, line 34 has several extra spaces after "Register" as well.

    0 讨论(0)
  • 2020-12-30 19:53

    Why this problem occurs even when all of your jade seems valid is highlighted in this github issue. Quoting from the original issue itself:

    The warning is because !{} and #{} are for interpolation within text. i.e. you have to be in(side) a text (block) to start with. You should use = and != to buffer JavaScript expressions.

    This means that the !{} and #{} are only to be used if you are interpolating within an existing text-block. Something like coffee-script's #{} interpolation here:

    a = "Hi #{name}!"
    

    translates to (in javascript)

    a = "Hi " + name + "!";
    

    Thus, in Jade too, you'll use the !{} and !{} within a running text (a paragraph or a string). To just output a string from a variable without explicitly starting a new text-block, you'd use = or !=.

    .row
      != marked(val)
    .another-row
      = marked(val)
    

    An alternative would be to explicitly start a new text-block as so:

    .row 
      | !{marked(val)}
    
    .another-row 
      | #{marked(val)}
    
    0 讨论(0)
  • 2020-12-30 19:57

    I got this error when using the !{} syntax and had an extra return:

    .row 
      !{marked(val)}
    

    should be:

    .row !{marked(val)}
    
    0 讨论(0)
  • 2020-12-30 19:57

    Alternatively you cna have this problem if you have you something like this..

    \t \t p    Foo
    \t \t p \t Foo
    

    I have had the above answer also generate this error so we're both technically right. ;)

    Also, if you use vim. You can see spaces by doing,

    :set hlsearch
    / /
    
    0 讨论(0)
提交回复
热议问题