comparison test/test_templating.py @ 6275:bda491248fd8

Handle exception raised from markdown processing If an exception is raised from the markdown processor, return plain text to the user.
author John Rouillard <rouilj@ieee.org>
date Thu, 22 Oct 2020 20:43:29 -0400
parents 474de62f4ce0
children 957a0fc20021
comparison
equal deleted inserted replaced
6274:474de62f4ce0 6275:bda491248fd8
458 # renderer, look for '<br' and require three of them. 458 # renderer, look for '<br' and require three of them.
459 m = p.markdown() 459 m = p.markdown()
460 self.assertEqual(3, m.count('<br')) 460 self.assertEqual(3, m.count('<br'))
461 461
462 def test_string_markdown_code_block(self): 462 def test_string_markdown_code_block(self):
463 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'embedded code block\n\n```\nline 1\nline 2\n```\n\nnew paragraph')) 463 ''' also verify that embedded html is escaped '''
464 self.assertEqual(p.markdown().strip().replace('\n\n', '\n'), u2s(u'<p>embedded code block</p>\n<pre><code>line 1\nline 2\n</code></pre>\n<p>new paragraph</p>')) 464 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'embedded code block <pre>\n\n```\nline 1\nline 2\n```\n\nnew </pre> paragraph'))
465 self.assertEqual(p.markdown().strip().replace('\n\n', '\n'), u2s(u'<p>embedded code block &lt;pre&gt;</p>\n<pre><code>line 1\nline 2\n</code></pre>\n<p>new &lt;/pre&gt; paragraph</p>'))
466
467 def test_string_markdown_code_block_attribute(self):
468 ''' also verify that embedded html is escaped '''
469 p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'embedded code block <pre>\n\n``` python\nline 1\nline 2\n```\n\nnew </pre> paragraph'))
470 m = p.markdown().strip()
471 print(m)
472 if type(self) == MistuneTestCase:
473 self.assertEqual(m.replace('\n\n','\n'), '<p>embedded code block &lt;pre&gt;</p>\n<pre><code class="lang-python">line 1\nline 2\n</code></pre>\n<p>new &lt;/pre&gt; paragraph</p>')
474 elif type(self) == MarkdownTestCase:
475 self.assertEqual(m.replace('\n\n','\n'), '<p>embedded code block &lt;pre&gt;</p>\n<pre><code class="language-python">line 1\nline 2\n</code></pre>\n<p>new &lt;/pre&gt; paragraph</p>')
476 else: # markdown2 doesn't handle attributes with code blocks
477 # so processing it returns original text
478 self.assertEqual(m.replace('\n\n', '\n'), u2s(u'embedded code block &lt;pre&gt;\n``` python\nline 1\nline 2\n```\nnew &lt;/pre&gt; paragraph'))
479
465 480
466 @skip_mistune 481 @skip_mistune
467 class MistuneTestCase(TemplatingTestCase, MarkdownTests) : 482 class MistuneTestCase(TemplatingTestCase, MarkdownTests) :
468 def setUp(self): 483 def setUp(self):
469 TemplatingTestCase.setUp(self) 484 TemplatingTestCase.setUp(self)

Roundup Issue Tracker: http://roundup-tracker.org/