summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2013-06-16 20:54:44 -0400
committerWaylan Limberg <waylan@gmail.com>2013-06-16 20:54:44 -0400
commitbf0791a5687a4c1248d69ce040620b3bb79a95ac (patch)
treed5b51a7ac133486eab03e03f99524bb17a985398
parentf37e3b99e41ceec54684c67538665d19687478c3 (diff)
downloadpython-markdown-bf0791a5687a4c1248d69ce040620b3bb79a95ac.tar.gz
AbbrExtension now handles abbreviations nested in other markup.
Just set each abreviation as an AtomicString. Given the nature of abbreviations, they are not likely to ever contain any other markup anyway. Also added a test. Fixes #224. Thanks for the report @JakeChampion.
-rw-r--r--markdown/extensions/abbr.py4
-rw-r--r--tests/test_extensions.py9
2 files changed, 11 insertions, 2 deletions
diff --git a/markdown/extensions/abbr.py b/markdown/extensions/abbr.py
index 5e46f1d..3f8a443 100644
--- a/markdown/extensions/abbr.py
+++ b/markdown/extensions/abbr.py
@@ -28,7 +28,7 @@ from __future__ import unicode_literals
from . import Extension
from ..preprocessors import Preprocessor
from ..inlinepatterns import Pattern
-from ..util import etree
+from ..util import etree, AtomicString
import re
# Global Vars
@@ -88,7 +88,7 @@ class AbbrPattern(Pattern):
def handleMatch(self, m):
abbr = etree.Element('abbr')
- abbr.text = m.group('abbr')
+ abbr.text = AtomicString(m.group('abbr'))
abbr.set('title', self.title)
return abbr
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index cb27a30..cce2adf 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -27,6 +27,15 @@ class TestAbbr(unittest.TestCase):
'and a <abbr title="Abbreviation Reference">REF</abbr>. Ignore '
'REFERENCE and ref.</p>')
+ def testNestedAbbr(self):
+ """ Test Nested Abbreviations. """
+ text = '[ABBR](/foo) and _ABBR_\n\n' + \
+ '*[ABBR]: Abreviation'
+ self.assertEqual(self.md.convert(text),
+ '<p><a href="/foo"><abbr title="Abreviation">ABBR</abbr></a> '
+ 'and <em><abbr title="Abreviation">ABBR</abbr></em></p>')
+
+
class TestCodeHilite(unittest.TestCase):
""" Test codehilite extension. """