How do I escape HTML with Jinja2 so that it can be used as a string in JavaScript (jQuery)?
If I were using Django's templating system I could write:
$("#mydiv").append("{{ html_string|escapejs }}");
Django's |escapejs
filter would escape things in html_string
(eg quotes, special chars) that could break the intended use of this code block, but Jinja2 does not seem to have an equivalent filter (am I wrong here?).
Is there a cleaner solution than copying/pasting the code from Django?
html_string
doesn't contain any harmful chars.