diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 6d93e47..c9bc9a2 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -1,4 +1,4 @@ -from bs4 import BeautifulSoup, NavigableString +from bs4 import BeautifulSoup, NavigableString, Comment import re import six @@ -75,7 +75,9 @@ class MarkdownConverter(object): # Convert the children first for el in node.children: - if isinstance(el, NavigableString): + if isinstance(el, Comment): + continue + elif isinstance(el, NavigableString): text += self.process_text(six.text_type(el)) else: text += self.process_tag(el, convert_children_as_inline) @@ -146,7 +148,7 @@ class MarkdownConverter(object): if convert_as_inline: return text - return '\n' + line_beginning_re.sub('> ', text) if text else '' + return '\n' + (line_beginning_re.sub('> ', text) + '\n\n') if text else '' def convert_br(self, el, text, convert_as_inline): if convert_as_inline: diff --git a/setup.py b/setup.py index b09c80d..498879d 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read() pkgmeta = { '__title__': 'markdownify', '__author__': 'Matthew Tretter', - '__version__': '0.6.3', + '__version__': '0.6.4', } diff --git a/tests/test_advanced.py b/tests/test_advanced.py index 4c480d7..7ee61d2 100644 --- a/tests/test_advanced.py +++ b/tests/test_advanced.py @@ -4,3 +4,13 @@ from markdownify import markdownify as md def test_nested(): text = md('
This is an example link.
') assert text == 'This is an [example link](http://example.com/).\n\n' + + +def test_ignore_comments(): + text = md("") + assert text == "" + + +def test_ignore_comments_with_other_tags(): + text = md("example link") + assert text == "[example link](http://example.com/)" diff --git a/tests/test_conversions.py b/tests/test_conversions.py index edaefbc..a32bf65 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -75,12 +75,16 @@ def test_b_spaces(): def test_blockquote(): - assert md('Hello').strip() == '> Hello' + assert md('
Hello') == '\n> Hello\n\n' + + +def test_blockquote_with_paragraph(): + assert md('
Hello
handsome
') == '\n> Hello\n\nhandsome\n\n' def test_nested_blockquote(): - text = md('And she was like').strip() - assert text == '> And she was like \n> > Hello' + text = md('Hello
And she was like') + assert text == '\n> And she was like \n> > Hello\n> \n> \n\n' def test_br():Hello