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

Data rendered inside the <head> tag is automatically moved to <body> #259

Open
adrdilauro opened this issue May 15, 2023 · 1 comment
Open

Comments

@adrdilauro
Copy link

adrdilauro commented May 15, 2023

Something very similar has already been reported in #176. That issue is very old though, so I am not sure whether it's the same problem or not.

I have the following (simplified) render call:

import { render } from 'ejs';

const template = `
  <!DOCTYPE html>
  <html>
    <head>
      <title>
        Title of the page
      </title>

      <svg id="icons">
        <%- icons %>
      </svg>

      <%- styles %>
    </head>

    <body>
      Body goes here...
    </body>
  </html>
`;

const rendered = render(template, {
  icons: `
    <symbol viewBox="...">
      <g>...</g>
    </symbol>

    <symbol viewBox="...">
      <g>...</g>
    </symbol>

    <symbol viewBox="...">
      <g>...</g>
    </symbol>
  `,
  styles: `
    <style>
      .style1 { ... };
      
      .style 2 { ... };
    </style>
  `,
});

When printing "rendered" into the node console, the resulting document looks like this:

<!DOCTYPE html>
<html>
  <head>
    <title>
      Title of the page
    </title>
  </head>

  <body>
    <svg id="icons">
      <symbol viewBox="...">
        <g>...</g>
      </symbol>

      <symbol viewBox="...">
        <g>...</g>
      </symbol>

      <symbol viewBox="...">
        <g>...</g>
      </symbol>
    </svg>

    <style>
      .style1 { ... };
      
      .style 2 { ... };
    </style>
    
    Body goes here...
  </body>
</html>

For some reason, the <style> and <svg> tags are moved automatically inside the body. Is there any configuration I am missing?

@limitLam
Copy link

limitLam commented May 15, 2023 via email

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

2 participants