tests-always-included/mo

Ignoring blocks

Closed this issue · 2 comments

Hi,

I'd like to be able to document how my templates work in my blog, but I'm having trouble compiling pages which contain templates examples, because mo is always parsing them - I'd like to be able to force mo to skip certain blocks:

Some markdown here.

{{#ignore}}
These {{braces}} should be printed literally, not parsed and evaluated.
{{/ignore}}

More {{parsed}} text here, which `mo` actually does parse & evaluate.

Is there any easy way to achieve this?

Thanks :)

Not without rewriting how mo works, such as including a tokenizer or AST or other amazing technology that will handle the nested braces. Normally one will use syntax like this

{{! This is a comment }}

That won't work because you want to include the closing delimiter (}}) inside your comment.

{{! This is a comment but it {{fails}} on the embedded mustache syntax }}

The parser right now will stop the comment at the first set of close braces, which is (I believe) in-line with how the official spec would have it. I do not believe you are able to do what you want this way.

Another option is to use something that will equate to false.

{{false}}
    This is all hidden.
    Even the use of {{variables}} is ignored.
{{/false}}

Is that what you are looking to do?

fidian commented

One idea would be to switch the delimiters. This was just added to mo and I'd recommend giving that a shot.

I can reopen this issue if you still have issues with it.