aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/inlinepatterns.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2014-09-25 16:07:07 -0400
committerWaylan Limberg <waylan.limberg@icloud.com>2014-09-26 10:29:48 -0400
commit8358bb3c569026d9775859bcdbd2611fc9499420 (patch)
treeebc59beddea170c21df1d8ccfc889120599a11ab /markdown/inlinepatterns.py
parent9082ed45deef99a0ff3c20aaa9f2c9b63e576838 (diff)
downloadmarkdown-8358bb3c569026d9775859bcdbd2611fc9499420.tar.gz
markdown-8358bb3c569026d9775859bcdbd2611fc9499420.tar.bz2
markdown-8358bb3c569026d9775859bcdbd2611fc9499420.zip
Better nested STRONG EM support.
Fixes #253. Thanks to @facelessuser for the tests. Although I removed a bunch of weird ones (even some that passed) from his PR (#342). For the most part, there is no definitive way for those to be parsed. So there is no point of testing for them. In most of those situations, authors should be mixing underscores and astericks so it is clear what is intended.
Diffstat (limited to 'markdown/inlinepatterns.py')
-rw-r--r--markdown/inlinepatterns.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py
index e990418..b63bc8c 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["em_strong"] = DoubleTagPattern(EM_STRONG_RE, 'strong,em')
+ inlinePatterns["strong_em"] = DoubleTagPattern(STRONG_EM_RE, 'em,strong')
inlinePatterns["strong"] = SimpleTagPattern(STRONG_RE, 'strong')
inlinePatterns["emphasis"] = SimpleTagPattern(EMPHASIS_RE, 'em')
if md_instance.smart_emphasis:
@@ -100,7 +101,8 @@ 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***
+EM_STRONG_RE = r'(\*|_){3}(.+?)\2(.*?)\2{2}' # ***strongem*** or ***em*strong**
+STRONG_EM_RE = r'(\*|_){3}(.+?)\2{2}(.*?)\2' # ***strong**em*
SMART_EMPHASIS_RE = r'(?<!\w)(_)(?!_)(.+?)(?<!_)\2(?!\w)' # _smart_emphasis_
EMPHASIS_2_RE = r'(_)(.+?)\2' # _emphasis_
LINK_RE = NOIMG + BRK + \
@@ -276,6 +278,8 @@ class DoubleTagPattern(SimpleTagPattern):
el1 = util.etree.Element(tag1)
el2 = util.etree.SubElement(el1, tag2)
el2.text = m.group(3)
+ if len(m.groups())==5:
+ el2.tail = m.group(4)
return el1