Whitespace Slurping with expression/output tag'<%=, <%-'.
See original GitHub issueFeature: Add support for having expression/output tags which support removing white space before them.
Description: Need expressions tag which can also remove the white space before the tag.
Its a combination of <%=
and <%_
.
Tags Introduced:
<%=_
Outputs the value into the template (escaped), strips all whitespace before it<%-_
Outputs the unescaped value into the template, strips all whitespace before it
Use case: I want to write markdown inside the EJS template. Since markdown heavily relies on indentation(and whitespaces), I want my EJS code to be indented in itself but not adding extra white space to markdown.
Example
For generating a markdown like following.
Heading
- No: 1
- No: 2
Basic implementation.
<% if(condition) {%>
<%= '**Heading**' %>
<% [1,2].forEach((i) => {%>
<%= '* No: '+i %>
<% }) %>
<% } %>
To write indented code.
Implementation with existing tag(‘Whitespace Slurping’ ).
<% if(condition ) {%>
<%_ %><%= '**Heading**' %>
<% [1,2].forEach((i) => {%>
<%_ %><%= '* No: '+i %>
<% }) %>
<% } %>
Implementation with new tag.
<% if(condition ) {%>
<%=_ '**Heading**' %>
<% [1,2].forEach((i) => {%>
<%=_ '* No: '+i %>
<% }) %>
<% } %>
Proposal: #PR 290
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
For loops in ejs - html - Stack Overflow
'<%- %>' this is help to print html code as it is. <% 'Scriptlet' tag, for control-flow, no output; <%_ 'Whitespace Slurping' Scriptlet...
Read more >EJS Templating - Profound Logic Documentation
EJS provides special tags that can be used within the HTML: <% 'Scriptlet' tag, for control-flow, no output; <%_ 'Whitespace Slurping' ...
Read more >What is EJS? | reading-notes - GitHub Pages
ESJ tags. ESJ uses these tags: <% 'Scriptlet' tag - for control-flow, no output; <%_ 'Whitespace Slurping' - Scriptlet tag, strips all whitespace...
Read more >EJS trim Tags - <%_ , %> and <%% , -%> (4 tags) - Reddit
<%_ 'Whitespace Slurping' Scriptlet tag, strips all whitespace before it. -%> Trim-mode ('newline slurp') tag, trims following newline.
Read more >3.0.2 - ejs - npm
... slurping') with -%> ending tag; Whitespace-trim mode (slurp all ... <%_ 'Whitespace Slurping' Scriptlet tag, strips all whitespace ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Definitely seems more reasonable to provide hooks to this for a plugin. We already have too many different permutations of whitespace stripping or formatting directly in EJS. Rather than building more and more facilities for handling formatting, we should be making it easy for people to offload that formatting to their chosen tools. I’m going to close this issue now, although I would love some input on an API for making plugins easy to use.
That does look weird, though. @mde Is this a feature we want?