diff options
author | Waylan Limberg <waylan@gmail.com> | 2008-11-04 18:54:09 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2008-11-04 18:54:09 -0500 |
commit | 47c8ba4a561d0100feebca93ff0f288757e6e69d (patch) | |
tree | ff595a660c7245fb14ab585cf4bb6cace618fa5e | |
parent | a4106db7aff9e961f0c40a738f19ccf06a7cae6c (diff) | |
download | markdown-47c8ba4a561d0100feebca93ff0f288757e6e69d.tar.gz markdown-47c8ba4a561d0100feebca93ff0f288757e6e69d.tar.bz2 markdown-47c8ba4a561d0100feebca93ff0f288757e6e69d.zip |
Added support to Definition List extension for blank lines between terms and first def. Includes tests. That was easier than expected.
-rw-r--r-- | markdown_extensions/def_list.py | 7 | ||||
-rw-r--r-- | tests/extensions-x-def_list/loose_def_list.html | 21 | ||||
-rw-r--r-- | tests/extensions-x-def_list/loose_def_list.txt | 20 |
3 files changed, 48 insertions, 0 deletions
diff --git a/markdown_extensions/def_list.py b/markdown_extensions/def_list.py index a988e13..30e0f82 100644 --- a/markdown_extensions/def_list.py +++ b/markdown_extensions/def_list.py @@ -99,9 +99,16 @@ class DefListParser(markdown.MarkdownParser): elif paragraph: terms, defs, paragraph = self._getDefs(paragraph) if defs: + if not terms: + # The previous paragraph must be the terms + c = parent_elem.getchildren() + if c and c[-1].tag == "p" and c[-1].text: + terms = c[-1].text.split("\n") + parent_elem.remove(c[-1]) # check for extra paragraphs of a def extradef, lines = self.detectTabbed(lines) defs[-1].extend(extradef) + # process the terms and defs self._processDef(parent_elem, terms, defs) if len(paragraph): self._MarkdownParser__processParagraph(parent_elem, diff --git a/tests/extensions-x-def_list/loose_def_list.html b/tests/extensions-x-def_list/loose_def_list.html new file mode 100644 index 0000000..98fdec8 --- /dev/null +++ b/tests/extensions-x-def_list/loose_def_list.html @@ -0,0 +1,21 @@ +<p>some text</p> +<dl> +<dt>term 1</dt> +<dd> +<p>def 1-1</p> +</dd> +<dd> +<p>def 2-2</p> +</dd> +<dt>term 2</dt> +<dt>term 3</dt> +<dd> +<p>def 2-1 +line 2 of def 2-1</p> +</dd> +<dd> +<p>def 2-2</p> +<p>par 2 of def2-2</p> +</dd> +</dl> +<p>more text</p>
\ No newline at end of file diff --git a/tests/extensions-x-def_list/loose_def_list.txt b/tests/extensions-x-def_list/loose_def_list.txt new file mode 100644 index 0000000..24cd6a4 --- /dev/null +++ b/tests/extensions-x-def_list/loose_def_list.txt @@ -0,0 +1,20 @@ +some text + +term 1 + +: def 1-1 + +: def 2-2 + +term 2 +term 3 + +: def 2-1 + line 2 of def 2-1 + +: def 2-2 + + par 2 of def2-2 + +more text + |