Merge pull request #34 from BrunoMiguens/add-ignore-comment-tags
Add ignore comment tags
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -4,3 +4,13 @@ from markdownify import markdownify as md
|
||||
def test_nested():
|
||||
text = md('<p>This is an <a href="http://example.com/">example link</a>.</p>')
|
||||
assert text == 'This is an [example link](http://example.com/).\n\n'
|
||||
|
||||
|
||||
def test_ignore_comments():
|
||||
text = md("<!-- This is a comment -->")
|
||||
assert text == ""
|
||||
|
||||
|
||||
def test_ignore_comments_with_other_tags():
|
||||
text = md("<!-- This is a comment --><a href='http://example.com/'>example link</a>")
|
||||
assert text == "[example link](http://example.com/)"
|
||||
|
||||
Reference in New Issue
Block a user