Skip to content

Commit effa7a8

Browse files
author
Waylan Limberg
committed
Attr_List Extension now also supports nested ol's.
Not sure how I missed that when committing ea4af0d. Also as a side-effect, this fixes Python-Markdown#230 - which brought my previous oversight to my attention. Thanks for the report @divisoryang. Also added some tests - including tests of list items without attr_lists. Sometimes I forget to test markup that does not use an extension when an extension is enabled. That's what resulted in Python-Markdown#230 being reported.
1 parent 5529647 commit effa7a8

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

markdown/extensions/attr_list.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,25 @@ def run(self, doc):
8484
# header: check for attrs at end of line
8585
RE = self.HEADER_RE
8686
if len(elem) and elem.tag == 'li':
87-
# special case list items. children may include a ul.
88-
ul = None
89-
# find the ul position
87+
# special case list items. children may include a ul or ol.
88+
pos = None
89+
# find the ul or ol position
9090
for i, child in enumerate(elem):
91-
if child.tag == 'ul':
92-
ul = i
91+
if child.tag in ['ul', 'ol']:
92+
pos = i
9393
break
94-
if ul is None and elem[-1].tail:
95-
# use tail of last child. no ul.
94+
if pos is None and elem[-1].tail:
95+
# use tail of last child. no ul or ol.
9696
m = RE.search(elem[-1].tail)
9797
if m:
9898
self.assign_attrs(elem, m.group(1))
9999
elem[-1].tail = elem[-1].tail[:m.start()]
100-
if ul > 0 and elem[ul-1].tail:
101-
# use tail of last child before ul
102-
m = RE.search(elem[ul-1].tail)
100+
elif pos > 0 and elem[pos-1].tail:
101+
# use tail of last child before ul or ol
102+
m = RE.search(elem[pos-1].tail)
103103
if m:
104104
self.assign_attrs(elem, m.group(1))
105-
elem[ul-1].tail = elem[ul-1].tail[:m.start()]
105+
elem[pos-1].tail = elem[pos-1].tail[:m.start()]
106106
elif elem.text:
107107
# use text. ul is first child.
108108
m = RE.search(elem.text)

tests/extensions/attr_list.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,26 @@ <h3 _:="{:" id="hash5">Bad Syntax</h3>
2626
<li class="subitem"><em class="emph">Item3-1</em></li>
2727
</ul>
2828
</li>
29-
</ul>
29+
<li>Item4<ul>
30+
<li>Item4-1</li>
31+
</ul>
32+
</li>
33+
<li>Item5</li>
34+
</ul>
35+
<p>And ordered lists too:</p>
36+
<ol>
37+
<li class="item">Item1</li>
38+
<li class="item">Item2<ol>
39+
<li class="subitem">Item2-1</li>
40+
</ol>
41+
</li>
42+
<li class="item"><em class="emph">Item3</em><ol>
43+
<li class="subitem"><em class="emph">Item3-1</em></li>
44+
</ol>
45+
</li>
46+
<li>Item4<ol>
47+
<li>Item4-1</li>
48+
</ol>
49+
</li>
50+
<li>Item5</li>
51+
</ol>

tests/extensions/attr_list.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,23 @@ Also a codespan: `{: .someclass}`{: .foo}.
4545
{: .item }
4646
* _Item3-1_{: .emph }
4747
{: .subitem }
48+
* Item4
49+
* Item4-1
50+
* Item5
51+
52+
And ordered lists too:
53+
54+
1. Item1
55+
{: .item }
56+
2. Item2
57+
{: .item }
58+
1. Item2-1
59+
{: .subitem }
60+
3. _Item3_{: .emph }
61+
{: .item }
62+
1. _Item3-1_{: .emph }
63+
{: .subitem }
64+
4. Item4
65+
1. Item4-1
66+
5. Item5
67+

0 commit comments

Comments
 (0)