creationix / haml-js

Haml ported to server-side Javascript. This is a traditional server-side templating language. Tested with node-js
MIT License
902 stars 110 forks source link

Multiline pipe appears not to be honored #88

Open StoneCypher opened 9 years ago

StoneCypher commented 9 years ago

The HAML Spec offers a multiline notation. A HAML transform built on this library which works on similar code fails with this error:

<pre class='error'>SyntaxError: Unexpected token |
  at Function.&lt;anonymous&gt; (/Users/project/node_modules/gulp-haml/node_modules/haml/lib/haml.js:595:29)
  at execute (/Users/project/node_modules/gulp-haml/node_modules/haml/lib/haml.js:602:8)
  at Function.render (/Users/project/node_modules/gulp-haml/node_modules/haml/lib/haml.js:587:12)
  at hamlStream (/Users/project/node_modules/gulp-haml/index.js:23:44)
  at wrappedMapper (/Users/project/node_modules/gulp-haml/node_modules/map-stream/index.js:84:19)
...
StoneCypher commented 9 years ago

The triggering code is the sample code from the specification

StoneCypher commented 9 years ago

From the spec:

The pipe character designates a multiline string. It’s placed at the end of a line (after some whitespace) and means that all following lines that end with | will be evaluated as though they were on the same line. Note that even the last line in the multiline block should end with |. For example:

%whoo
  %hoo= h(                       |
    "I think this might get " +  |
    "pretty long so I should " + |
    "probably make it " +        |
    "multiline so it doesn't " + |
    "look awful.")               |
  %p This is short.

is compiled to:

<whoo>
  <hoo>I think this might get pretty long so I should probably make it multiline so it doesn't look awful.</hoo>
  <p>This is short</p>
</whoo>

Instead a compilation failure occurs.

This in concert with https://github.com/creationix/haml-js/issues/74 make haml-js very difficult to use for practical real-world templates.

seballot commented 3 years ago

Fixed with #99