Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shouldn't lines containing comments (<%#) be deleted from output? #375

Open
nikolay-borzov opened this issue May 22, 2018 · 1 comment
Open

Comments

@nikolay-borzov
Copy link

nikolay-borzov commented May 22, 2018

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>
@myfonj
Copy link

myfonj commented May 22, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants