Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't format files with EJS inside opening HTML tags #11

Open
manuhabitela opened this issue Mar 11, 2024 · 2 comments
Open

Can't format files with EJS inside opening HTML tags #11

manuhabitela opened this issue Mar 11, 2024 · 2 comments

Comments

@manuhabitela
Copy link

manuhabitela commented Mar 11, 2024

Hi 👋

Thanks for the plugin :)

It seems I have an issue very similar to this closed one: #8

For example, prettier can't format this piece of code:

<button class="fr-btn" type="submit" <% if (locals.ariaLabel) { %>aria-label="<%= locals.ariaLabel %>"<% } %>>
    <%= label %>
</button>

Because of the test inside the button opening tag:

[error] src/[...].ejs: SyntaxError: Opening tag "button" not terminated. (14:5)
[error]   12 |         <% } %>
[error]   13 |     </span>
[error] > 14 |     <button class="fr-btn" type="submit" <% if (locals.ariaLabel) { %>aria-label="<%= locals.ariaLabel %>"<% } %>>
[error]      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]   15 |         <%= label %>
[error]   16 |     </button>
[error]   17 | </div>

I'm using the latest plugin version and latest prettier version. I also tried the nested EJS example in the readme and it crashes too.

Is there something I missed? Thanks!

@thomaspatrickwelborn
Copy link

thomaspatrickwelborn commented Jun 19, 2024

Experienced the same issue where a Syntax Error is generated when EJS closures occur within Markup Element Start Tag.

  • Prettier v3.3.2

Example A

INPUT

<!DOCTYPE html5>
<html lang="en">
  <head>
    <title></title>
    <% for (const $meta of $data.content.meta) { %>
      <meta 
        <% for(const $metaAttribute of $meta.attributes) { %>
	      <%= $metaAttr.key %>="<%= $metaAttr.val %>"
        <% } %>
      />
    <% } %>
  </head>
  <body>
  </body>
</html>

OUTPUT

SyntaxError: Opening tag "meta" not terminated. (6:7)
   4 |     <title></title>
   5 |     <% for (const $meta of $data.content.meta) { %>
>  6 |       <meta 
     |       ^^^^^^
>  7 |         <% for(const $metaAttribute of $meta.attributes) { %>
     | ^^^^^^^^^
   8 | 	      <%= $metaAttr.key %>="<%= $metaAttr.val %>"
   9 |         <% } %>
  10 |       />

Example B

It also appears that one of the given tests from the README fails, FYI:

INPUT

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

OUTPUT

SyntaxError: Opening tag "td" not terminated.
> 1 | <td <% if (styleData) { %>
    | ^^^^
  2 |   style="<%= styleData %>" <% } %>>
  3 |   <%= data %>
  4 |   <%= data %>

@sduzair
Copy link

sduzair commented Jul 30, 2024

@thomaspatrickwelborn I experienced the same issue. I am using the older prettier 2.8.8 as a workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants