aboutsummaryrefslogtreecommitdiffstats
path: root/markdown
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2013-06-16 22:24:28 -0400
committerWaylan Limberg <waylan@gmail.com>2013-06-16 23:21:40 -0400
commitea4af0db29a86466e4b8b9e694299054565a29ca (patch)
treec890b6b8ee09cb073dcaee93266fb87df6c8983a /markdown
parentccc9c3ec580cb93aeed81b8320746c164a7acdb5 (diff)
downloadmarkdown-ea4af0db29a86466e4b8b9e694299054565a29ca.tar.gz
markdown-ea4af0db29a86466e4b8b9e694299054565a29ca.tar.bz2
markdown-ea4af0db29a86466e4b8b9e694299054565a29ca.zip
Attr_List Extension now support attr_lists on nested lists.
A list item with a nested list complicates were the attr_list can be. Fixes #218. Thanks for the report @jpzimmer.
Diffstat (limited to 'markdown')
-rw-r--r--markdown/extensions/attr_list.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/markdown/extensions/attr_list.py b/markdown/extensions/attr_list.py
index c98aa85..2bea213 100644
--- a/markdown/extensions/attr_list.py
+++ b/markdown/extensions/attr_list.py
@@ -77,13 +77,40 @@ class AttrListTreeprocessor(Treeprocessor):
def run(self, doc):
for elem in doc.getiterator():
+ #import pdb; pdb.set_trace()
if isBlockLevel(elem.tag):
# Block level: check for attrs on last line of text
RE = self.BLOCK_RE
if isheader(elem):
# header: check for attrs at end of line
RE = self.HEADER_RE
- if len(elem) and elem[-1].tail:
+ if len(elem) and elem.tag == 'li':
+ # special case list items. children may include a ul.
+ ul = None
+ # find the ul position
+ for i, child in enumerate(elem):
+ if child.tag == 'ul':
+ ul = i
+ break
+ if ul is None and elem[-1].tail:
+ # use tail of last child. no ul.
+ 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)
+ if m:
+ self.assign_attrs(elem, m.group(1))
+ elem[ul-1].tail = elem[ul-1].tail[:m.start()]
+ elif elem.text:
+ # use text. ul is first child.
+ m = RE.search(elem.text)
+ if m:
+ self.assign_attrs(elem, m.group(1))
+ elem.text = elem.text[:m.start()]
+ elif len(elem) and elem[-1].tail:
# has children. Get from tail of last child
m = RE.search(elem[-1].tail)
if m: