aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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>