ejs
ejs copied to clipboard
Shouldn't lines containing comments (<%#) be deleted from output?
I'm generating an XML file (using ejs-webpack-builder
):
<OfficeApp>
<%# Id should be unique %>
<Id>911dca27-02ec-42c4-8cc3-857c3acfa8f9</Id>
</OfficeApp>
And get result:
<OfficeApp>
<Id>911dca27-02ec-42c4-8cc3-857c3acfa8f9</Id>
</OfficeApp>
I'd expect:
<OfficeApp>
<Id>911dca27-02ec-42c4-8cc3-857c3acfa8f9</Id>
</OfficeApp>
I tried using _%>
, but it adds offset from the line with a comment to the next line:
<OfficeApp>
<Id>911dca27-02ec-42c4-8cc3-857c3acfa8f9</Id>
</OfficeApp>
Can confirm that _%>
whitespace slurping works strange indeed:
1
2
<%# comment _%>
2
1
produces
1
2
2
1
As a not-so-pretty-but-functional workaround you can use both-ways slurped JavaScript comment (or any valid JavaScript expression as long as it does not contain %>
) in scriptlet tag:
1
2
<%_/*
block
comment
*/-%>
<%_
// line comment
_%>
<%_
"string literal"
_%>
<%_`
template
string
`_%>
2
1
(can end with either _%>
or -%>
) produces
1
2
2
1
As a side note from my experience: to get "well-indented" output of something 'templated' it is usually better to employ some extra "beautifier" in the build pipeline. Nice source of something with e.g. nested includes are seldom solvable otherwise… Plus, you remove possibility of human error and get uniform rules.