squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
592 stars 82 forks source link

Issue with EOL parsing. #117

Closed tabarra closed 5 years ago

tabarra commented 5 years ago

Describe the bug The library seems to be ignoring LF as line endings.

To Reproduce Consider this code:

datasets: [{
    //Change squirrelly tag: {{tags(--,--)/}}
    data: --chartData|safe--
    //Changing it back: --tags({{,}})/--
}]

Expected behavior

datasets: [{
    //Change squirrelly tag: 
    data: example
    //Changing it back: 
}]

Output received

datasets: [{
    //Change squirrelly tag:     data: example    //Changing it back: }]

Browser [e.g. chrome, safari] Any

Additional context Works perfectly when the template is using CRLF.

nebrelbug commented 5 years ago

Hi @tabarra thanks for opening the issue!

Squirrelly is set to remove \n if it follows [tagOpen]content[tagClose], but not \r\n.

Since LF just uses \n, Squirrelly will replace the newline right after a tag, so {{myTag}}\n will become options.myTag. But with CRLF, \n doesn't directly follow the tag, it follows \r, so it's not replaced.

Since Squirrelly only replaces the first newline, you can write:

datasets: [{
    //Change squirrelly tag: {{tags(--,--)/}}

    data: --chartData|safe--

    //Changing it back: --tags({{,}})/--

}]

This issue will be resolved in version 8, where you'll have more control over whitespace

nebrelbug commented 5 years ago

By the way, were you able to try out my tip in #115?

tabarra commented 5 years ago

Thank you for the reply.
Closing this issue :)