mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.79k stars 843 forks source link

closing tag is removed even when no opening tag before => troublesome for CSS #773

Closed bfredo123 closed 1 month ago

bfredo123 commented 1 month ago

Hi, I am using EJS to allow HTML content personalization. I use custom open/closeDelimieters: { } instead of < >.

Unfortunatelty, another node component generates HTML, with embedded CSS like "{ ... width: 75%}". As a result, when invoking EJS on this HTML, in order to personalize it, the "75%}" is replaced by "75", which obviously makes the CSS corrupted, and the display of the HTML is broken.

I would expect that EJS does not remove this "%}", because there is no preceding "{%" or "{%=" tag.

Is there an option to ask EJS not to remove the unbalanced closing tags? Or some kind of workaround? (I cannot change the "{}" delimiters to other chars).

I have read issue #284 which seems related, but could not find any solution.

Many thanks in advance!

mde commented 1 month ago

An implementation which works the way you suggest it should, would add a ton of complexity that would be unnecessary for all but the most exceptional of cases, as you describe.

Number one, you are using custom tags. Number two, you are using another library that generates code which end up aping the custom tags you have specified, resulting in broken code.

There are multiple possible workarounds here. You could stop using custom tags ("Doctor, it hurts when I do 'this.'"), or you could possibly clean the code generated by the problematic Node library so that there are always spaces around the brackets in the embedded CSS.