title: Escape strings for JavaScript using Jinja2?
body: <p>How do I escape HTML with Jinja2 so that it can be used as a string in JavaScript (jQuery)?</p>
  
  <p>If I were using Django's templating system I could write:</p>
  
  <pre><code>$("#mydiv").append("{{ html_string|escapejs }}");
  </code></pre>
  
  <p>Django's <a href="https://github.com/django/django/blob/ebc773ada3e4f40cf5084268387b873d7fe22e8b/django/utils/html.py#L63" rel="noreferrer"><code>|escapejs</code> filter</a> would escape things in <code>html_string</code> (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?).</p>
  
  <p>Is there a cleaner solution than copying/pasting the code from Django?</p>