question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Whitespace Slurping with expression/output tag'<%=, <%-'.

See original GitHub issue

Feature: 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:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mdecommented, Mar 29, 2018

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.

0reactions
RyanZimcommented, Aug 4, 2017

That does look weird, though. @mde Is this a feature we want?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found