title: BeautifulSoup replaceWith() method adding escaped html, want it unescaped
body: <p>I have a python method (<a href="https://djangosnippets.org/snippets/2072/" rel="noreferrer">thank to this snippet</a>) that takes some html and wraps <code>&lt;a&gt;</code> tags around ONLY unformatted links, using BeautifulSoup and Django's urlize:</p>
  
  <pre><code>from django.utils.html import urlize
  from bs4 import BeautifulSoup
  
  def html_urlize(self, text):
      soup = BeautifulSoup(text, "html.parser")
  
      print(soup)
  
      textNodes = soup.findAll(text=True)
      for textNode in textNodes:
          if textNode.parent and getattr(textNode.parent, 'name') == 'a':
              continue  # skip already formatted links
          urlizedText = urlize(textNode)
          textNode.replaceWith(urlizedText)
  
      print(soup)
  
      return str(soup)
  </code></pre>
  
  <p>Sample input text (as output by the first print statement) is this:</p>
  
  <pre><code>this is a formatted link &lt;a href="http://google.ca"&gt;http://google.ca&lt;/a&gt;, this one is unformatted and should become formatted: http://google.ca
  </code></pre>
  
  <p>The resulting return text (as output by the second print statement) is this:</p>
  
  <pre><code>this is a formatted link &lt;a href="http://google.ca"&gt;http://google.ca&lt;/a&gt;, this one is unformatted and should become formatted: &amp;lt;a href="http://google.ca"&amp;gt;http://google.ca&amp;lt;/a&amp;gt;
  </code></pre>
  
  <p>As you can see, it is formatting the link, but it's doing it with escaped html, so when I print it in a template <code>{{ my.html|safe }}</code> it doesn't render as html.</p>
  
  <p>So how can I get these tags that are added with urlize to be unescaped, and render properly as html? I suspect this has something do do with me using it as a method instead of a template filter?  I can't actually find the docs on this method, it doesn't appear in <a href="https://docs.djangoproject.com/en/1.8/ref/utils/#module-django.utils.html" rel="noreferrer">django.utils.html</a>.</p>
  
  <p>Edit: It appears the escaping actually happen in this line: <code>textNode.replaceWith(urlizedText)</code>.</p>