Multiple Lines for Long Attribute Value in Jade / Pug

后端 未结 6 816
遥遥无期
遥遥无期 2020-12-28 12:07

How do we write a long attribute value over multiple lines in Jade / Pug?

SVG paths tend to be really long. We want to write an attribute value over multiple lines t

6条回答
  •  有刺的猬
    2020-12-28 12:57

    I have this same problem but in a knockoutjs context. I used the backslash like so. Previously:

    div(data-bind="template: {name: 'ingredient-template', data: $data}")
    

    Now:

    div(data-bind="template: {\
        name: 'ingredient-template',\
        data: $data}")
    

    Note: The backslash must be followed immediately by a newline. I'm not sure if this is the 'official' way, I just did it and it seems to work. One downside of this method is the strings then get rendered with the white space intact. So the above example gets rendered as:

    This might make it unusable for your example.

    Edit Thanks Jon. The var idea from your comment is probably better though still not ideal. Something like:

    -var arg  = "M10 315 "
    -arg += "L 110 215 "
    -arg += "A 30 50 0 0 1 162.55 162.45 "
    -arg += "L 172.55 152.45 "
    -arg += "A 30 50 -45 0 1 215.1 109.9 "
    -arg += "L 315 10"
    h3 Arcs
      svg(width="320px", height="320px")
        path(d=arg, 
        stroke="black", fill="green", 
        stroke-width="2", fill-opacity="0.5")
    

    Not sure that the extra characters are worth the reduction in line length.

提交回复
热议问题