From 321e9eb5f64ee15474d2853efee5ed3cffe47a64 Mon Sep 17 00:00:00 2001 From: Bruno Miguens Date: Fri, 5 Feb 2021 19:38:24 +0000 Subject: [PATCH 1/4] Add ignore comment tags --- markdownify/__init__.py | 6 ++++-- tests/test_advanced.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 6d93e47..5c008d3 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) diff --git a/tests/test_advanced.py b/tests/test_advanced.py index 4c480d7..2f8aeb1 100644 --- a/tests/test_advanced.py +++ b/tests/test_advanced.py @@ -4,3 +4,11 @@ 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/)" \ No newline at end of file From 457454c713ce03752ca96309a796e66275edc9dd Mon Sep 17 00:00:00 2001 From: Bruno Miguens Date: Fri, 5 Feb 2021 19:41:43 +0000 Subject: [PATCH 2/4] Add new line at the end of file --- tests/test_advanced.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_advanced.py b/tests/test_advanced.py index 2f8aeb1..7ee61d2 100644 --- a/tests/test_advanced.py +++ b/tests/test_advanced.py @@ -5,10 +5,12 @@ 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/)" \ No newline at end of file + assert text == "[example link](http://example.com/)" From f320cf87ffa92fb0499eff1bbaf5db5c1fddf564 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sun, 21 Feb 2021 20:53:41 +0100 Subject: [PATCH 3/4] closing #25 and #18 Adds newlines after blockquotes, allowing for paragraphs after a blockquote. Due to merging problems with @lucafrance 's code I had to quickly copy and paste their code. Thanks for the contribution! --- markdownify/__init__.py | 2 +- tests/test_conversions.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 5c008d3..c9bc9a2 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -148,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/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
Hello
').strip() - assert text == '> And she was like \n> > Hello' + text = md('
And she was like
Hello
') + assert text == '\n> And she was like \n> > Hello\n> \n> \n\n' def test_br(): From ed406d3206d6509b9c8c349fd92ebacaf5768729 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Sun, 21 Feb 2021 20:57:57 +0100 Subject: [PATCH 4/4] bump to v0.6.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ec7dea2..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.1', + '__version__': '0.6.4', }