diff options
author | Waylan Limberg <waylan@gmail.com> | 2013-09-26 20:32:10 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2013-09-26 20:32:10 -0400 |
commit | 884d25b7aad62478ae53eb9a3759bc2617959843 (patch) | |
tree | ad950ba1aedf750e88065ced9942d1b92f429894 /markdown/inlinepatterns.py | |
parent | 62e5485c0f4292717f48b4c16cdd6894c891716f (diff) | |
download | python-markdown-issue253.tar.gz |
Partial fix for #253.issue253
This actually fixes the immediate problem. The method on the inlinePattern
returns the correct subtree. However, for some reason, the parent element
of that subtree is later stripped of all content (perhaps by the
inlineplaceholder stuff). So, for example, given this input:
***foo** bar*
The inlinepattern returns:
<em><strong>foo</strong> bar</em>
However, later it is reduced to:
<em></em>
Interestingly, this still works:
***foo***
Correctly becomes:
<strong><em>foo</em></strong>
I'm guessing that the tail on the `em` tag in the first instance is tripping
things up some how.
Diffstat (limited to 'markdown/inlinepatterns.py')
-rw-r--r-- | markdown/inlinepatterns.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index de957ef..04c2351 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -75,7 +75,8 @@ def build_inlinepatterns(md_instance, **kwargs): inlinePatterns["html"] = HtmlPattern(HTML_RE, md_instance) inlinePatterns["entity"] = HtmlPattern(ENTITY_RE, md_instance) inlinePatterns["not_strong"] = SimpleTextPattern(NOT_STRONG_RE) - inlinePatterns["strong_em"] = DoubleTagPattern(STRONG_EM_RE, 'strong,em') + inlinePatterns["strong_em"] = DoubleTagPattern(A_STRONG_EM_RE, 'strong,em') + inlinePatterns["strong_em_"] = DoubleTagPattern(U_STRONG_EM_RE, 'strong,em') inlinePatterns["strong"] = SimpleTagPattern(STRONG_RE, 'strong') inlinePatterns["emphasis"] = SimpleTagPattern(EMPHASIS_RE, 'em') if md_instance.smart_emphasis: @@ -99,8 +100,9 @@ NOIMG = r'(?<!\!)' BACKTICK_RE = r'(?<!\\)(`+)(.+?)(?<!`)\2(?!`)' # `e=f()` or ``e=f("`")`` ESCAPE_RE = r'\\(.)' # \< EMPHASIS_RE = r'(\*)([^\*]+)\2' # *emphasis* -STRONG_RE = r'(\*{2}|_{2})(.+?)\2' # **strong** -STRONG_EM_RE = r'(\*{3}|_{3})(.+?)\2' # ***strong*** +STRONG_RE = r'(\*{2}|_{2})(.+?)\2' # **strong** +A_STRONG_EM_RE = r'\*{3}(.+?)\*{2}([^*]*)\*' # ***strongem*** +U_STRONG_EM_RE = r'_{3}(.+?)_{2}([^_]*)_' # ___strongem___ SMART_EMPHASIS_RE = r'(?<!\w)(_)(?!_)(.+?)(?<!_)\2(?!\w)' # _smart_emphasis_ EMPHASIS_2_RE = r'(_)(.+?)\2' # _emphasis_ LINK_RE = NOIMG + BRK + \ @@ -276,9 +278,17 @@ class DoubleTagPattern(SimpleTagPattern): """ def handleMatch(self, m): tag1, tag2 = self.tag.split(",") - el1 = util.etree.Element(tag1) - el2 = util.etree.SubElement(el1, tag2) - el2.text = m.group(3) + if m.group(3): + # This is a match for `***foo** bar*`. Group 3 contains ` bar`. + el1 = util.etree.Element(tag2) + el2 = util.etree.SubElement(el1, tag1) + el2.text = m.group(2) + el2.tail = m.group(3) + else: + # This is a match for `***foo***`. We don't switch tag order here. + el1 = util.etree.Element(tag1) + el2 = util.etree.SubElement(el1, tag2) + el2.text = m.group(2) return el1 |