padolsey/SIML

Add 'break out' feature

padolsey opened this issue · 12 comments

Add a syntax that allows you to break out of SIML and simply write regular HTML.

E.g.

div
    ul
        !!!
        <!-- some real html -->
        <li>...</li>
        !!!

Syntax undecided though. Possibly adopt a similar approach to Jade with the pipe.

HTML could also be allowed in the heredocs, so authors could write:

div
    ul
        '''
        <!-- some real html -->
        <li>...</li>
        '''

Of course, these strings get auto-escaped, but it would also be possible to differentiate between double and single quoted heredocs (""", '''), where one or the other wouldn’t get escaped?

Initial implementation done in breakout branch: a0603e8

Not 100% I'm happy with the grave-accent being used as the delimiter but I think I prefer it to '!' or '|'...

So, as it's currently implemented, you can do:

div
    ul
        `
        <!-- Real HTML here -->
        `

A single tick/grave-accent is used to delimit on single or multi-lines.

@wooorm Currently siml doesn't support heredocs, although that code will work because it's parsed as:

  '' // empty string
  '\n        <!-- some real html -->\n        <li>...</li>        '
  '' // empty string

i.e. the main string surrounded by two empty strings.

Maybe I should add explicit support for ''' and """ though..? That would make it easier to write text without having to escape every quote (`" Blah " blah blah ").

Oh right, that’s why those "heredocs" acted so funky :).
And adding these might also be nice to not escape/encode things inside a script, aka, the following SIML...

script
    """
    a > b
    """

…will get converted to:

<script>

    a > b

</script>

If we add the back-tick for plain unescaped HTML would that solve the <script> issue? So you could just do:

script
    ```
    a > b
    ```

Certainly!

But…
Would the triple back-tick be a real "heredoc", or, would SIML parse the following unescaped?

script `a > b`

SIML would parse that as unescaped. The heredoc would just be decorative or useful if you want to include the normal delimiting character in the actual string, e.g.

script
    ```
        // ` ` ` ` `
    ```

Feature's in master. Bumped to 0.3.3.

Can you push 0.3.3 to the npm registry? Currently 0.3.2 is the latest version.

See https://npmjs.org/package/siml

@Anaphase Sorry about that -- it should be updated now