From b32cba5558d964f3445f20bdd44af8ed1cc2df83 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 4 Nov 2010 20:51:24 -0400 Subject: Fixed Ticket 74. AtomicStrings should now be ackowledged (and preserved) in all instances. This was a real pain to debug, but an easy fix once I found it. Thanks to obs for the report. --- markdown/treeprocessors.py | 7 ++++++- tests/test_apis.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/markdown/treeprocessors.py b/markdown/treeprocessors.py index 0c5a99a..d2af0dc 100644 --- a/markdown/treeprocessors.py +++ b/markdown/treeprocessors.py @@ -14,7 +14,9 @@ def build_treeprocessors(md_instance, **kwargs): def isString(s): """ Check if it's string """ - return isinstance(s, unicode) or isinstance(s, str) + if not isinstance(s, util.AtomicString): + return isinstance(s, basestring) + return False class Processor: @@ -204,6 +206,9 @@ class InlineProcessor(Treeprocessor): strartIndex = end else: text = data[strartIndex:] + if isinstance(data, util.AtomicString): + # We don't want to loose the AtomicString + text = util.AtomicString(text) linkText(text) data = "" diff --git a/tests/test_apis.py b/tests/test_apis.py index 0de4727..ebbc24f 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -325,3 +325,48 @@ class testETreeComments(unittest.TestCase): pretty.run(self.comment) self.assertEqual(markdown.html4.to_html_string(self.comment), '\n') + + +class testAtomicString(unittest.TestCase): + """ Test that AtomicStrings are honored (not parsed). """ + + def setUp(self): + md = markdown.Markdown() + self.inlineprocessor = md.treeprocessors['inline'] + + def testString(self): + """ Test that a regular string is parsed. """ + tree = markdown.util.etree.Element('div') + p = markdown.util.etree.SubElement(tree, 'p') + p.text = u'some *text*' + new = self.inlineprocessor.run(tree) + self.assertEqual(markdown.html4.to_html_string(new), + '

some text

') + + def testSimpleAtomicString(self): + """ Test that a simple AtomicString is not parsed. """ + tree = markdown.util.etree.Element('div') + p = markdown.util.etree.SubElement(tree, 'p') + p.text = markdown.util.AtomicString(u'some *text*') + new = self.inlineprocessor.run(tree) + self.assertEqual(markdown.html4.to_html_string(new), + '

some *text*

') + + def testNestedAtomicString(self): + """ Test that a nested AtomicString is not parsed. """ + tree = markdown.util.etree.Element('div') + p = markdown.util.etree.SubElement(tree, 'p') + p.text = markdown.util.AtomicString(u'*some* ') + span1 = markdown.util.etree.SubElement(p, 'span') + span1.text = markdown.util.AtomicString(u'*more* ') + span2 = markdown.util.etree.SubElement(span1, 'span') + span2.text = markdown.util.AtomicString(u'*text* ') + span3 = markdown.util.etree.SubElement(span2, 'span') + span3.text = markdown.util.AtomicString(u'*here*') + span3.tail = markdown.util.AtomicString(u' *to*') + span2.tail = markdown.util.AtomicString(u' *test*') + span1.tail = markdown.util.AtomicString(u' *with*') + new = self.inlineprocessor.run(tree) + self.assertEqual(markdown.html4.to_html_string(new), + '

*some* *more* *text* *here* *to* *test* *with*

') + -- cgit v1.2.3