Closed DaafSamson closed 11 months ago
So, I'm probably doing things not needed at all and just missing the point. But I needed a solution and this is what I did.
I'm working in powershell (hey, it's an environment). Since there was no project available that met my criteria, I created one: https://github.com/Palloquin/PSStubble/. It's based on Stubble.
I added an option to do custom white-space replacement. To achieve this I added my own extra tags to to Mustache standard: {|
and |}
I use these two regular expressions to clean up after doing a standard (stubble based) Mustache merge:
{\|\s*\|}((\r\n)|\r|\n)?
--> remove block sstarting and ending with my tags, with nothing but white-space between them, include a potential line-break after the tag
({\|)|(\|})
--> remove leftover tags
I simply replace with empty strings
This would result in something like this:
New template:
This is what we know about {{name}}:
{|{{#colour}}- Favourite colour is {{colour}}{{/colour}}|}
{|{{#fruit}}- Favourite fruit is {{fruit}}{{/fruit}}|}
{|{{#book}}- Favourite book is {{book}}{{/book}}|}
Output
This is what we know about James:
- Favourite colour is green
- Favourite book is War and peace
This is a quick and dirty hack, I'm sure I'm missing some edge cases, and could do better. I might not even need to do this at all, but heck, it works. I'm very open to comments
Any update here? Noone with the same problem?
I had to change mustach to fix a compatibility with the spec (see https://gitlab.com/jobol/mustach/-/issues/30)
Spec is: a line with a standalone tag is not emitted.
So writing your template as below should make the job
This is what we know about {{name}}:
{{#colour}}
- Favourite colour is {{colour}}
{{/colour}}
{{#fruit}}
- Favourite fruit is {{fruit}}
{{/fruit}}
{{#book}}
- Favourite book is {{book}}
{{/book}}
I removed the {| |}
so this is perhaps not a valuable solution in that case ....
The above solution is correct. Closing this, as this repository is only about the Mustache website, not about the template language.
Hi, I'm using Mustache to merge plain text templates. I have the following scenario:
data
template
Result:
Note the glaring gap between the two lines... Now, in a HTML template this would not be and issue, white spaces and empty lines are eaten by the browser and the result flows nicely. In a plain text environment though, this is an issue.
Is there an established way to deal with this? Is there a construct that drops the line including the line break after the field?