aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/treeprocessors.py7
-rw-r--r--tests/test_apis.py45
2 files changed, 51 insertions, 1 deletions
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),
'<!--foo-->\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),
+ '<div><p>some <em>text</em></p></div>')
+
+ 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),
+ '<div><p>some *text*</p></div>')
+
+ 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),
+ '<div><p>*some* <span>*more* <span>*text* <span>*here*</span> *to*</span> *test*</span> *with*</p></div>')
+