Python: add > escaping

This commit is contained in:
Ian Gulliver
2014-07-02 13:42:17 -07:00
parent 2e75804e30
commit 8a9f9acbaa
2 changed files with 6 additions and 3 deletions

View File

@@ -20,7 +20,10 @@ class TextNode(object):
return self.textContent
def __str__(self):
return self.textContent.replace('&', '&amp;').replace('<', '&lt;')
return (self.textContent
.replace('&', '&amp;')
.replace('<', '&lt;')
.replace('>', '&gt;'))
class Element(object):

View File

@@ -47,7 +47,7 @@ This is <del>strikethrough</del>, as is <del>this</del>. Source
code looks like <code>this</code>. Fixed width text looks like
<tt>this</tt>. <pre>This sentence is inline pre-formatted, which stops
'''''this from being bold and italic.'''''</pre> We can also
stop &lt;u>this from being underlined&lt;/u>, or just try
&lt;pre>interrupting cow style.&lt;/pre><blockquote>This is a blockquote</blockquote></p><p><h2>Header 2</h2><h3>Header 3 <i>with italics</i></h3><h4>Header 4</h4><h5>Header 5</h5><h6>Header 6</h6><hr></hr><ul><li>Item 1a</li></ul><ul><li>Item 1b</li></ul><ul><ul><li>Item 2</li></ul></ul><ul><ul><ul><li>Item 3</li></ul></ul></ul><ul><li>Item 1c</li></ul><ol><li>Item 1a</li></ol><ol><li>Item 1b</li></ol><ol><ol><li>Item 2</li></ol></ol><ol><ol><ol><li>Item 3</li></ol></ol></ol><ol><li>Item 1c</li></ol><def>I don't really understand what a definition is</def><blockquote>But blockquotes are easy</blockquote><blockquote2>Even larger ones</blockquote2><blockquote5>And really huge ones</blockquote5><pre>This line is pre-formatted and &lt;del>not interpolated&lt;/del>
stop &lt;u&gt;this from being underlined&lt;/u&gt;, or just try
&lt;pre&gt;interrupting cow style.&lt;/pre&gt;<blockquote>This is a blockquote</blockquote></p><p><h2>Header 2</h2><h3>Header 3 <i>with italics</i></h3><h4>Header 4</h4><h5>Header 5</h5><h6>Header 6</h6><hr></hr><ul><li>Item 1a</li></ul><ul><li>Item 1b</li></ul><ul><ul><li>Item 2</li></ul></ul><ul><ul><ul><li>Item 3</li></ul></ul></ul><ul><li>Item 1c</li></ul><ol><li>Item 1a</li></ol><ol><li>Item 1b</li></ol><ol><ol><li>Item 2</li></ol></ol><ol><ol><ol><li>Item 3</li></ol></ol></ol><ol><li>Item 1c</li></ol><def>I don't really understand what a definition is</def><blockquote>But blockquotes are easy</blockquote><blockquote2>Even larger ones</blockquote2><blockquote5>And really huge ones</blockquote5><pre>This line is pre-formatted and &lt;del&gt;not interpolated&lt;/del&gt;
</pre><pre>This line is also pre-formatted
</pre></p></wikidoc>"""