aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2013-07-19 18:58:50 -0400
committerWaylan Limberg <waylan@gmail.com>2013-07-19 18:58:50 -0400
commiteffa7a8aaace52b466fdd19ffd97e5e33e2a9a3a (patch)
treeccac6f799184842b73cdad06ae9ed51c2d96da92
parent5529647cd03468a7d2ae085c86b397d2b2379ab8 (diff)
downloadmarkdown-effa7a8aaace52b466fdd19ffd97e5e33e2a9a3a.tar.gz
markdown-effa7a8aaace52b466fdd19ffd97e5e33e2a9a3a.tar.bz2
markdown-effa7a8aaace52b466fdd19ffd97e5e33e2a9a3a.zip
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 #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 #230 being reported.
-rw-r--r--markdown/extensions/attr_list.py22
-rw-r--r--tests/extensions/attr_list.html24
-rw-r--r--tests/extensions/attr_list.txt20
3 files changed, 54 insertions, 12 deletions
diff --git a/markdown/extensions/attr_list.py b/markdown/extensions/attr_list.py
index a8884e4..161c448 100644
--- a/markdown/extensions/attr_list.py
+++ b/markdown/extensions/attr_list.py
@@ -84,25 +84,25 @@ class AttrListTreeprocessor(Treeprocessor):
# header: check for attrs at end of line
RE = self.HEADER_RE
if len(elem) and elem.tag == 'li':
- # special case list items. children may include a ul.
- ul = None
- # find the ul position
+ # special case list items. children may include a ul or ol.
+ pos = None
+ # find the ul or ol position
for i, child in enumerate(elem):
- if child.tag == 'ul':
- ul = i
+ if child.tag in ['ul', 'ol']:
+ pos = i
break
- if ul is None and elem[-1].tail:
- # use tail of last child. no ul.
+ if pos is None and elem[-1].tail:
+ # use tail of last child. no ul or ol.
m = RE.search(elem[-1].tail)
if m:
self.assign_attrs(elem, m.group(1))
elem[-1].tail = elem[-1].tail[:m.start()]
- if ul > 0 and elem[ul-1].tail:
- # use tail of last child before ul
- m = RE.search(elem[ul-1].tail)
+ elif pos > 0 and elem[pos-1].tail:
+ # use tail of last child before ul or ol
+ m = RE.search(elem[pos-1].tail)
if m:
self.assign_attrs(elem, m.group(1))
- elem[ul-1].tail = elem[ul-1].tail[:m.start()]
+ elem[pos-1].tail = elem[pos-1].tail[:m.start()]
elif elem.text:
# use text. ul is first child.
m = RE.search(elem.text)
diff --git a/tests/extensions/attr_list.html b/tests/extensions/attr_list.html
index b1032f9..b1ed85c 100644
--- a/tests/extensions/attr_list.html
+++ b/tests/extensions/attr_list.html
@@ -26,4 +26,26 @@ And a <strong class="nest">nested <a class="linky2" href="http://example.com" ti
<li class="subitem"><em class="emph">Item3-1</em></li>
</ul>
</li>
-</ul> \ No newline at end of file
+<li>Item4<ul>
+<li>Item4-1</li>
+</ul>
+</li>
+<li>Item5</li>
+</ul>
+<p>And ordered lists too:</p>
+<ol>
+<li class="item">Item1</li>
+<li class="item">Item2<ol>
+<li class="subitem">Item2-1</li>
+</ol>
+</li>
+<li class="item"><em class="emph">Item3</em><ol>
+<li class="subitem"><em class="emph">Item3-1</em></li>
+</ol>
+</li>
+<li>Item4<ol>
+<li>Item4-1</li>
+</ol>
+</li>
+<li>Item5</li>
+</ol> \ No newline at end of file
diff --git a/tests/extensions/attr_list.txt b/tests/extensions/attr_list.txt
index 959c117..8ecfe44 100644
--- a/tests/extensions/attr_list.txt
+++ b/tests/extensions/attr_list.txt
@@ -45,3 +45,23 @@ Also a codespan: `{: .someclass}`{: .foo}.
{: .item }
* _Item3-1_{: .emph }
{: .subitem }
+* Item4
+ * Item4-1
+* Item5
+
+And ordered lists too:
+
+1. Item1
+ {: .item }
+2. Item2
+ {: .item }
+ 1. Item2-1
+ {: .subitem }
+3. _Item3_{: .emph }
+ {: .item }
+ 1. _Item3-1_{: .emph }
+ {: .subitem }
+4. Item4
+ 1. Item4-1
+5. Item5
+