title: Convert text to HTML comment in Python
body: <p>I have a Python script that generates some HTML. It does so using <a href="https://pypi.python.org/pypi/Markdown" rel="nofollow">the Python markdown library</a>. I'd like to stick the original Markdown text in a comment at the end of the HTML, where it will occasionally be useful for debugging purposes. I've tried just plunking the Markdown text after the end of the HTML, and it doesn't work for me (Firefox). So the way I imagine this working is that I run Markdown and then simply append the Markdown source, marked as a comment, after the HTML. However, HTML is apparently somewhat finicky about what it will allow in comments. The site htmlhelp.com gives the following advice after some discussion:</p>
  
  <blockquote>
    <p>For this reason, use the following simple rule to compose valid and accepted [portable] comments:<br>
        An HTML comment begins with "" and does not contain "--" or ">" anywhere in the comment.<br>
    <a href="http://www.htmlhelp.com/reference/wilbur/misc/comment.html" rel="nofollow">(source)</a></p>
  </blockquote>
  
  <p>So it looks like I need to do some escaping or something to get my bunch of markdown text into a form that HTML will accept as a comment. Is there an existing tool that will help me do this?</p>