title: Django. Jquery. escaping string with quotes error
body: <p>In a small forum, any user can save posts. Sometimes those posts include words surrounded by quotes ( " " ). This gives me an error when I try to handle those strings with javascript.</p>
  
  <p>I wrote some jquery code that uses the django variable like this:</p>
  
  <pre><code>new_text = "{{text|safe}}";
  $("#text_p").text(new_text);
  </code></pre>
  
  <p>if I mark it as "safe" then javascript gives me a syntax error:</p>
  
  <pre><code>the text "(error here)word between quotes" the user posted
  </code></pre>
  
  <p>This is logical because javascript understands the quotes like this:</p>
  
  <pre><code>new_text = "this is the text "word between quotes" the user posted"
  </code></pre>
  
  <p>So, if I don't mark it as "safe" and let django escape the text, it doesn't give me an error, but the text looks like this:</p>
  
  <pre><code> the text &amp;quot;word between quotes&amp;quot the user posted
  </code></pre>
  
  <p>I don't know what to do, and I guess it may not be simple cause if I use single quotes to declare the javascript variable, I will have the same problem when the user posts a text with single quotes. If I use a regex to replace double quotes and not mark the text as "text|safe", then other tags will be escaped and the text will be full of "&lt;br /&amp;gt" etc. </p>
  
  <p>I have an idea that may work but is ugly and probably not the best option:
  including the text in a <code>&lt;p class = "hidden"&gt;</code> tag and then calling it using jquery.</p>
  
  <p>So, the question is, how do I solve this?, is there a better way? 
  Thanks in advance for your help.</p>
  
  <p><strong>EDIT</strong>:
  I created a <a href="http://runnable.com/U-V70djKNQxztWOj/problem-between-django-context-variables-with-quotes-and-javascript-for-python">Runnable</a> to explain it better.</p>