Skip to content

Commit 7fc1dfa

Browse files
committed
issue2551097 - fix call to markdown2 - fix fenced code blocks.
The invocation of fenced codeblock support in markdown2 was wrong. With this fixed the code that was used to test markdown processor exception handling no longer works. Fixed test case to make it pass. Added new test with invalid markdown that tests markdown exception handling. Also renamed test to include markdown. Makes using -k option in run_tests easier.
1 parent 46d650c commit 7fc1dfa

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

CHANGES.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ Fixed:
3737
- issue2551093 - return plain text if markdown formatter throws exception
3838
(reported by Cedric Krier, fix by John Rouillard)
3939
- issue2551094 - make simplemde handle line breaks the same as the
40-
backend markdown formmatters. (report: Cedric Krier, patch: Christof
40+
backend markdown formatters. (report: Cedric Krier, patch: Christof
4141
Meerwald)
4242
- issue2551092 - fix crash bug by aligning
4343
roundup.anypy.email_.decode_header with stdlib email.header and
44-
convert string to bytes for python 3. (Cedrick Krier)
44+
convert string to bytes for python 3.
45+
- issue2551097 - fix underlying bug in use of fenced codeblocks with
46+
markdown2. Fix for issue2551093 to prevent exception trigger.
47+
(patch: Cedric Krier)
4548

4649
Features:
4750
- issue2550522 - Add 'filter' command to command-line

roundup/cgi/templating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Markdown(markdown2.Markdown):
7070
_safe_protocols = re.compile('(?!' + ':|'.join([re.escape(s) for s in _disable_url_schemes]) + ':)', re.IGNORECASE)
7171

7272
def _extras(config):
73-
extras = { 'fenced-code-blocks' : True }
73+
extras = { 'fenced-code-blocks' : {} }
7474
if config['MARKDOWN_BREAK_ON_NEWLINE']:
7575
extras['break-on-newline'] = True
7676
return extras

test/test_templating.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,17 @@ def test_string_markdown_code_block_attribute(self):
473473
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>')
474474
elif type(self) == MarkdownTestCase:
475475
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'))
476+
else:
477+
self.assertEqual(m.replace('\n\n', '\n'), '<p>embedded code block &lt;pre&gt;</p>\n<div class="codehilite"><pre><span></span><code><span class="n">line</span> <span class="mi">1</span>\n<span class="n">line</span> <span class="mi">2</span>\n</code></pre></div>\n<p>new &lt;/pre&gt; paragraph</p>')
479478

480-
def test_break_on_newline(self):
479+
def test_markdown_return_text_on_exception(self):
480+
''' string is invalid markdown. missing end of fenced code block '''
481+
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'))
482+
m = p.markdown().strip()
483+
print(m)
484+
self.assertEqual(m.replace('\n\n','\n'), '<p>embedded code block &lt;pre&gt;</p>\n<p>``` python\nline 1\nline 2</p>\n<p>new &lt;/pre&gt; paragraph</p>')
485+
486+
def test_markdown_break_on_newline(self):
481487
self.client.db.config['MARKDOWN_BREAK_ON_NEWLINE'] = True
482488
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with\nline break\ntwice.'))
483489
m = p.markdown()

0 commit comments

Comments
 (0)