padolsey / SIML

Simplified Markup
MIT License
97 stars 5 forks source link

Add 'break out' feature #3

Closed padolsey closed 11 years ago

padolsey commented 11 years ago

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.

wooorm commented 11 years ago

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?

padolsey commented 11 years ago

Initial implementation done in breakout branch: https://github.com/padolsey/SIML/commit/a0603e86bceececa6247d8e463f737823b80e3e8

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.

padolsey commented 11 years ago

@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 ").

wooorm commented 11 years ago

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>
padolsey commented 11 years ago

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

script
a > b
```
wooorm commented 11 years ago

Certainly!

wooorm commented 11 years ago

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

script `a > b`
padolsey commented 11 years ago

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
    // ` ` ` ` `
```
padolsey commented 11 years ago

Feature's in master. Bumped to 0.3.3.

Anaphase commented 11 years ago

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

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

padolsey commented 11 years ago

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

Anaphase commented 11 years ago

@padolsey Thanks!