mustache / spec

The Mustache spec.
MIT License
364 stars 71 forks source link

Escape syntax? #103

Closed fletcher closed 1 year ago

fletcher commented 6 years ago

I can't tell if the spec is dead or not, but in the hopes it is not...

I was looking for a lightweight templating system to work with various languages, and found the Mustache "family". It looks like it will fit my needs well. My goal is to incorporate it into MultiMarkdown, or at the very least ensure that they play nicely together.

One trivial issue is the need to be able to write about Mustache without triggering Mustache templating. For example, if I am documenting how Mustache works, I would want to be able to write that one could use a tag like {{foo}}.

However, if that document is passed through Mustache, then {{foo}} is likely to be deleted from the text. There doesn't seem to be a quick way to "escape" the syntax to avoid triggering a parse. For example, something like \{{foo\}} or {\{foo}\} or whatever. (I don't think I missed an existing syntax for this, but if I did then my apologies!)

I realize that I could change the delimiters to something else, write about the syntax, and then change them back, but that seems needlessly complicated.

I am happy to create my own solution in my implementation, but would much prefer to standardize on something if it a) exists or b) is coming.

Any thoughts??

Thanks for a great idea!!

jgonggrijp commented 1 year ago

Sorry for the late reply. Set Delimiter is the way to go. It's ony 24 characters, including linebreaks, regardless of how much Mustache code you want to display verbatim:

{{=<< >>=}}
{{! verbatim Mustache here }}
<<={{ }}=>>

That said, a compliant Mustache implementation should not recognize {\{foo}} as a tag. If the text is first passed through a Mustache engine and then through MultiMarkdown, and the latter takes care of replacing \{ by { again, you should get what you want.

Yet another option, which should work in any case since Markdown is a superset of HTML, is to write &#123;{foo}}.