prettier-plugin-ejs

Prettier EJS Plugin

MIT License

Downloads
7.6K
Stars
19
Committers
1

Prettier Plugin for EJS

This plugin formats EJS markup in html files. It uses the default html parser and just marks EJS specific tags as comments.

Installation

npm install --save-dev prettier-plugin-ejs

For Prettier v2, the plugin will be loaded automatically.

For Prettier v3, you'll need to manually load the plugin:

prettier --plugin=prettier-plugin-ejs --write .

Please check Prettier Docs for other loading methods.

Example

Before

<div>
  <!-- prettier-ignore -->
  <div>
    <% if (condition) { %> <% } else if (condition) { %> <% } %>
  </div>

  <div class="<%= red %>"><%= 1 > 0 %></div>

  <textarea><%= text %></textarea>
  <code><%= text %></code>
  <pre><%= text %></pre>
</div>

After

<div>
  <div>
    <% if (condition) { %>
    <% } else if (condition) { %>
    <% } %>
  </div>

  <div class="<%= red %>"><%= 1 > 0 %></div>

  <textarea><%= text %></textarea>
  <code><%= text %></code>
  <pre><%= text %></pre>
</div>

Nested Tag

<td <% if (styleData) { %>
  style="<%= styleData %>" <% } %>>
  <%= data %>
  <%= data %>
</td>

Note

Tags which contains the greater then symbol > are ignored.