Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Issue #365 Bold/Italic nesting fix
The logic for the current regex for strong/em and em/strong was sound,
but the way it was implemented caused some unintended side effects.
Whether it is a quirk with regex in general or just with Python’s re
engine, I am not sure.  Put basically `(\*|_){3}`  causes issues with
nested bold/italic. So, allowing the group to be defined, and then
using the group number to specify the remaining sequential chars is a
better way that works more reliably `(\*|_)\2{2}.  Test from issue #365
was also added to check for this case in the future.
  • Loading branch information
facelessuser committed Nov 18, 2014
commit 609faad76b80ff10da0e471183ad0cede3221571
4 changes: 2 additions & 2 deletions markdown/inlinepatterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def build_inlinepatterns(md_instance, **kwargs):
ESCAPE_RE = r'\\(.)' # \<
EMPHASIS_RE = r'(\*)([^\*]+)\2' # *emphasis*
STRONG_RE = r'(\*{2}|_{2})(.+?)\2' # **strong**
EM_STRONG_RE = r'(\*|_){3}(.+?)\2(.*?)\2{2}' # ***strongem*** or ***em*strong**
STRONG_EM_RE = r'(\*|_){3}(.+?)\2{2}(.*?)\2' # ***strong**em*
EM_STRONG_RE = r'(\*|_)\2{2}(.+?)\2(.*?)\2{2}' # ***strongem*** or ***em*strong**
STRONG_EM_RE = r'(\*|_)\2{2}(.+?)\2{2}(.*?)\2' # ***strong**em*
SMART_EMPHASIS_RE = r'(?<!\w)(_)(?!_)(.+?)(?<!_)\2(?!\w)' # _smart_emphasis_
EMPHASIS_2_RE = r'(_)(.+?)\2' # _emphasis_
LINK_RE = NOIMG + BRK + \
Expand Down
4 changes: 3 additions & 1 deletion tests/misc/nested-patterns.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
<strong><a href="http://example.com"><em>link</em></a></strong>
<strong><a href="http://example.com"><em>link</em></a></strong>
<a href="http://example.com"><strong><em>link</em></strong></a></p>
<p><strong><em>I am <strong><em>italic</em> and</strong> bold</em> I am <code>just</code> bold</strong></p>
<p><strong><em>I am <strong><em>italic</em> and</strong> bold</em> I am <code>just</code> bold</strong></p>
<p>Example <strong><em>bold italic</em></strong> on the same line <strong><em>bold italic</em></strong>.</p>
<p>Example <strong><em>bold italic</em></strong> on the same line <strong><em>bold italic</em></strong>.</p>
4 changes: 4 additions & 0 deletions tests/misc/nested-patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ __[*link*](http://example.com)__
[***link***](http://example.com)

***I am ___italic_ and__ bold* I am `just` bold**

Example __*bold italic*__ on the same line __*bold italic*__.

Example **_bold italic_** on the same line **_bold italic_**.