title: Dumb quotes into smart quotes only for text not HTML code
body: <p>I’m transforming dumb quotes into smart quotes in a <code>contenteditable</code> but the problem is that it also replaces them inside HTML elements like:</p>
  
  <pre><code>&lt;a href=“something” title=“something”
  </code></pre>
  
  <p>thus making them invalid. I want to only do it for user’s text. Here’s the catch. I have to keep the original formatting elements, so I can’t do something like:</p>
  
  <pre><code>clean($('#something_container').text());
  </code></pre>
  
  <p>This would remove all HTML elements (formatting) when returned. Here’s the code that I have:</p>
  
  <pre><code>content = clean($('#post_content').html());
  $('#post_content').html(content);
  
  // replaces ", ', --, &lt;div&gt; with &lt;p&gt;
  function clean(html) {
    html = html.replace(/'\b/g, "\u2018")  // opening singles
           .replace(/\b'/g, "\u2019")  // closing singles
           .replace(/"\b/g, "\u201c")  // opening doubles
           .replace(/\b"/g, "\u201d")  // closing doubles
           .replace(/--/g,  "\u2014") // em-dashes
           .replace(/&lt;div&gt;/g, "&lt;p&gt;")  //&lt;div&gt; to &lt;p&gt;
           .replace(/&lt;\/div&gt;/g, "&lt;/p&gt;"); //&lt;/div&gt; to &lt;/p&gt;
    return html;
  };
  </code></pre>
  
  <p>What would be the best (most efficient) way to replace dumb quotes only in user’s text and skip the HTML tags like <code>&lt;img src="" /&gt;</code>? Thanks!</p>