question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignoring ejs script tags (ejs)

See original GitHub issue

Is it possible for cheerio to handle or ignore ejs tags like <% ... %>. I’m finding when I call $.html() it mangles the contents.

Great lib though 😃

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mbernathcommented, May 18, 2015

+1

For those who also have EJS code within attributes, e.g.<img src="<%= pictureUrl %>" alt="">, here is another workaround:

  var ejsCache = [];
  html = html.replace(/<%(.*?)%>/g, function (match) {
    ejsCache.push(match);
    return 'cachedejsstart' + (ejsCache.length-1) + 'cachedejsend';
  });
  // ... Perform operations here ...
  html = html.replace(/cachedejsstart(\d*)cachedejsend/g,function (match, num) {
    return ejsCache[parseInt(num)];
  });
1reaction
furqanZafarcommented, Jan 27, 2015

+1

Possible workaround:

  1. replace ejs tags with html comments
str.replace(/<%((.|\s)*?)%>/g, function(match, subMatch){ return "<!-- <%"+subMatch+"%> -->" });
  1. perform jquery operations …
$("head").append($("<script/>").attr("src", "http://dynamic.js"));
  1. remove the comments from the ejs tags
$.html().replace(/<!-- <%((.|\s)*?)%> -->/g, (match, subMatch){ return "<%"+subMatch+"%>"});
Read more comments on GitHub >

github_iconTop Results From Across the Web

ejs tags causing errors inside the script tag - Stack Overflow
i am trying to use ejs tags inside an internal script tag in an ejs template.. the code works, but "vs code" still...
Read more >
Serving Dynamic HTML using Embedded JavaScript (EJS)
Embedded JavaScript (EJS) is a JavaScript templating engine that lets you generate dynamic HTML plain JavaScript and EJS tags.
Read more >
Embedded JavaScript: Everything you need to know to get ...
EJS is mostly useful whenever you have to output HTML with a lot of ... The content of the tag will be automatically...
Read more >
Ignoring Code - Prettier
To exclude files from formatting, create a .prettierignore file in the root of your project. .prettierignore uses gitignore syntax. Example: # Ignore artifacts: ......
Read more >
Node.js v19.3.0 Documentation
Script cached data; DEP0111: process.binding(); DEP0112: dgram private APIs ... deepEqual(obj1, obj3); // OK // Prototypes are ignored: assert.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found