From b91a37be0ab019fa1ee0b94014a6ed0c7ff5dbf5 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 8 Sep 2014 22:37:45 -0400 Subject: Code Blocks must always be AtomicStrings Fixes #340. The "inline" TreeProcessor runs before the "prettify" TreeProcessor, but the "smarty" TreeProcessor (wich is just another instance of `InlineProcessor`) runs after the "prettify" TreeProcessor. The problem was that the "prettify" TreeProcessor was losing the AtomicString quality of the text of code blocks (any operation on a string creates a new string. When that string is an AtomicString, the new string must explicitly be declared as an AtomicString. As the "prettify" TreeProcessor cleans up newlines on code blocks, it was changing the AtomicString to a normal string. And as `InlineProcessor` identifies what elements to skip solely by whether the text is an AtomicString, the "smarty" instance was running on code blocks. Importantly, I added a test of code blocks and spans for smarty, so this shouldn't break again. --- markdown/treeprocessors.py | 2 +- tests/extensions/smarty.html | 6 +++++- tests/extensions/smarty.txt | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/markdown/treeprocessors.py b/markdown/treeprocessors.py index 113ad3c..a82141a 100644 --- a/markdown/treeprocessors.py +++ b/markdown/treeprocessors.py @@ -358,4 +358,4 @@ class PrettifyTreeprocessor(Treeprocessor): pres = root.getiterator('pre') for pre in pres: if len(pre) and pre[0].tag == 'code': - pre[0].text = pre[0].text.rstrip() + '\n' + pre[0].text = util.AtomicString(pre[0].text.rstrip() + '\n') diff --git a/tests/extensions/smarty.html b/tests/extensions/smarty.html index 0907a73..6305060 100644 --- a/tests/extensions/smarty.html +++ b/tests/extensions/smarty.html @@ -22,4 +22,8 @@ Anführungszeichen-»Chevrons«

'Escaped' "quotes"
Escaped ellipsis...

‘Escaped "quotes" in real ones’
-'“Real” quotes in escaped ones'

\ No newline at end of file +'“Real” quotes in escaped ones'

+

Skip "code" -- --- 'spans' ....

+
Also skip "code" 'blocks'
+foo -- bar --- baz ...
+
\ No newline at end of file diff --git a/tests/extensions/smarty.txt b/tests/extensions/smarty.txt index 3b034cf..35fb219 100644 --- a/tests/extensions/smarty.txt +++ b/tests/extensions/smarty.txt @@ -28,4 +28,9 @@ Escaped \-- ndash Escaped ellipsis\... 'Escaped \"quotes\" in real ones' -\'"Real" quotes in escaped ones\' \ No newline at end of file +\'"Real" quotes in escaped ones\' + +Skip `"code" -- --- 'spans' ...`. + + Also skip "code" 'blocks' + foo -- bar --- baz ... -- cgit v1.2.3