beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.64k stars 1.39k forks source link

Support for <% EJS %> templates #643

Open jawshooah opened 9 years ago

jawshooah commented 9 years ago

It would be awesome if js-beautify supported EJS templates out of the box. Currently the following code...

<ul>
<% for (var i = 0; i < supplies.length; i++) { %>
    <li><%= supplies[i] %></li>
<% } %>
</ul>

...is transformed into:

<ul>
    <% for (var i=0 ; i < supplies.length; i++) { %>
        <li>
            <%=s upplies[i] %>
        </li>
        <% } %>
</ul>
bitwiseman commented 9 years ago

Supporting this properly would be a big undertaking. Making it behave better might be possible without fully supporting it. This is lower priority than a number of other tasks for me. PR's welcome.

wangdabing commented 6 years ago

It seems to be possible https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify-html.js#L103

var token_type = multi_parser.token_type;  
if (multi_parser.token_text.substr(0, 2) === '<%') {  
    token_type = '';
}
switch (token_type) {
thomaspatrickwelborn commented 5 months ago

Seen this issue has been open for about 9 years. Commenting to express need for this feature.

My software uses EJS templates to generate text content for ES, CSS, and Markup Template Language (EJS) files. EJS generates text content then JS Beautify formats it then Node FS writes the file content.

I noticed that BeautifyJS supports some markup template languages (ERB, for example, which closely resembles EJS) through an optional templating configuration property.