aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/extensions/attr_list.py29
-rw-r--r--tests/extensions/attr_list.html13
-rw-r--r--tests/extensions/attr_list.txt11
3 files changed, 51 insertions, 2 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:
diff --git a/tests/extensions/attr_list.html b/tests/extensions/attr_list.html
index f50cd6a..b1032f9 100644
--- a/tests/extensions/attr_list.html
+++ b/tests/extensions/attr_list.html
@@ -15,4 +15,15 @@ And a <strong class="nest">nested <a class="linky2" href="http://example.com" ti
</code></pre>
<h3 id="hash3">No colon for compatability with Headerid ext</h3>
<p id="the_end">Also a codespan: <code class="foo">{: .someclass}</code>.</p>
-<h3 _:="{:" id="hash5">Bad Syntax</h3> \ No newline at end of file
+<h3 _:="{:" id="hash5">Bad Syntax</h3>
+<ul>
+<li class="item">Item1</li>
+<li class="item">Item2<ul>
+<li class="subitem">Item2-1</li>
+</ul>
+</li>
+<li class="item"><em class="emph">Item3</em><ul>
+<li class="subitem"><em class="emph">Item3-1</em></li>
+</ul>
+</li>
+</ul> \ No newline at end of file
diff --git a/tests/extensions/attr_list.txt b/tests/extensions/attr_list.txt
index cd7f398..959c117 100644
--- a/tests/extensions/attr_list.txt
+++ b/tests/extensions/attr_list.txt
@@ -34,3 +34,14 @@ Also a codespan: `{: .someclass}`{: .foo}.
{: #the_end}
### Bad Syntax { {: #hash5 }
+
+* Item1
+ {: .item }
+* Item2
+ {: .item }
+ * Item2-1
+ {: .subitem }
+* _Item3_{: .emph }
+ {: .item }
+ * _Item3-1_{: .emph }
+ {: .subitem }