Formatting ejs template files in emacs

1.2k Views Asked by At

Is there any emacs mode that can format properly the ejs template file.

Sample EJS template file

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <b> <%= doc.session_name %> </b>
    <ul>
      <% var p = {}; %>
      <% var coinInitialPositions = [-1, -1]; %>
      <% for (var i = 0; i < doc.moves.length; ++i) { %>
     <% if (doc.moves[i].type === 'dice_values') { %>
     <%     if (typeof p[doc.moves[i].player] === 'undefined') { %>
         <%        p[doc.moves[i].player] = []; %>
         <%     } %>
     <%     p[doc.moves[i].player] = p[doc.moves[i].player].concat(doc.moves[i].values); %>
     <% } %>

     <li>
        <%= i + " " + JSON.stringify(doc.moves[i]) %>
     </li>
      <% } %>
    </ul>
    <% for (var player in p) { %>
    <li>
      <b> <%= player + ": [" + p[player] + "]"%> </b>
    <li>
      <% } %>
    </body>
</head>
1

There are 1 best solutions below

0
On

You should look at web-mode.el which has very good compatibility with ejs