Skip to content

Commit 72c819a

Browse files
committed
Fix tail out of order issue
This issue was discovered when dealing with nested inlines. In treeprocessors.py it was incorrectly handling tails. In short, tail elements were being inserted earlier than they were supposed to be. In order to fix this, the insertion index should be incremented by 1 so that when the tails are inserted into the parent, they will be just after the child they came from. Also added a test in nested-patterns to catch this issue.
1 parent 57633f1 commit 72c819a

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

markdown/treeprocessors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def __processElementText(self, node, subnode, isText=True):
132132
childResult = self.__processPlaceholders(text, subnode, isText)
133133

134134
if not isText and node is not subnode:
135-
pos = list(node).index(subnode)
135+
pos = list(node).index(subnode) + 1
136136
else:
137137
pos = 0
138138

tests/misc/nested-patterns.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<strong><a href="http://example.com"><em>link</em></a></strong>
55
<strong><a href="http://example.com"><em>link</em></a></strong>
66
<strong><a href="http://example.com"><em>link</em></a></strong>
7-
<a href="http://example.com"><strong><em>link</em></strong></a></p>
7+
<a href="http://example.com"><strong><em>link</em></strong></a></p>
8+
<p><strong><em>I am <strong><em>italic</em> and</strong> bold</em> I am <code>just</code> bold</strong></p>

tests/misc/nested-patterns.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ __[_link_](http://example.com)__
55
__[*link*](http://example.com)__
66
**[_link_](http://example.com)**
77
[***link***](http://example.com)
8+
9+
***I am ___italic_ and__ bold* I am `just` bold**

0 commit comments

Comments
 (0)