aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2008-11-04 22:17:18 -0500
committerWaylan Limberg <waylan@gmail.com>2008-11-04 22:17:18 -0500
commit00f623253bc80e95921f6055a6db206b548857db (patch)
treee8b0ab1f6efa50b0e0d7a1a5e0f048e2dac35b98
parent47c8ba4a561d0100feebca93ff0f288757e6e69d (diff)
downloadmarkdown-00f623253bc80e95921f6055a6db206b548857db.tar.gz
markdown-00f623253bc80e95921f6055a6db206b548857db.tar.bz2
markdown-00f623253bc80e95921f6055a6db206b548857db.zip
Fixed Definition List extension to not wrap the content of defs in p tags when appropriate.
-rw-r--r--markdown_extensions/def_list.py13
-rw-r--r--tests/extensions-x-def_list/simple_def-lists.html12
2 files changed, 11 insertions, 14 deletions
diff --git a/markdown_extensions/def_list.py b/markdown_extensions/def_list.py
index 30e0f82..dcab3ed 100644
--- a/markdown_extensions/def_list.py
+++ b/markdown_extensions/def_list.py
@@ -105,11 +105,14 @@ class DefListParser(markdown.MarkdownParser):
if c and c[-1].tag == "p" and c[-1].text:
terms = c[-1].text.split("\n")
parent_elem.remove(c[-1])
+ looseList = 1
# check for extra paragraphs of a def
extradef, lines = self.detectTabbed(lines)
- defs[-1].extend(extradef)
+ if extradef:
+ looseList = 1
+ defs[-1].extend(extradef)
# process the terms and defs
- self._processDef(parent_elem, terms, defs)
+ self._processDef(parent_elem, terms, defs, looseList)
if len(paragraph):
self._MarkdownParser__processParagraph(parent_elem,
paragraph,
@@ -145,7 +148,7 @@ class DefListParser(markdown.MarkdownParser):
return Def
return []
- def _processDef(self, parentElem, terms, defs):
+ def _processDef(self, parentElem, terms, defs, looseList):
children = parentElem.getchildren()
if children and children[-1].tag == "dl":
dl = children[-1]
@@ -156,11 +159,11 @@ class DefListParser(markdown.MarkdownParser):
dt.text = term
for d in defs:
dd = etree.SubElement(dl, "dd")
- self.parseChunk(dd, d)
+ self.parseChunk(dd, d, looseList = looseList)
def _MarkdownParser__processParagraph(self, parentElem, paragraph, inList, looseList):
- if ( parentElem.tag == 'li'
+ if ((parentElem.tag == 'li' or parentElem.tag == 'dd')
and not (looseList or parentElem.getchildren())):
# If this is the first paragraph inside "li", don't
diff --git a/tests/extensions-x-def_list/simple_def-lists.html b/tests/extensions-x-def_list/simple_def-lists.html
index 7cb4d81..278e1ec 100644
--- a/tests/extensions-x-def_list/simple_def-lists.html
+++ b/tests/extensions-x-def_list/simple_def-lists.html
@@ -1,17 +1,11 @@
<p>Some text</p>
<dl>
<dt>term1</dt>
-<dd>
-<p>Def1</p>
-</dd>
+<dd>Def1</dd>
<dt>term2-1</dt>
<dt>term2-2</dt>
-<dd>
-<p>Def2-1</p>
-</dd>
-<dd>
-<p>Def2-2</p>
-</dd>
+<dd>Def2-1</dd>
+<dd>Def2-2</dd>
</dl>
<p>more text</p>
<dl>