Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ def _can_ignore(el):
parent_tags_for_children.add('_inline')

# if this tag is a preformatted element, add a '_noformat' parent pseudo-tag
if node.name in {'pre', 'code', 'kbd', 'samp'}:
# (unless the tag is stripped, as its contents are then output as plain text)
if node.name in {'pre', 'code', 'kbd', 'samp'} and self.should_convert_tag(node.name):
parent_tags_for_children.add('_noformat')

# Convert the children elements into a list of result strings.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def test_do_not_convert():
assert text == 'Some Text'


def test_strip_preformatted():
# stripped preformatted tags are output as plain text, so their contents are escaped
assert md('<code>*foo* &lt;b&gt;</code>', strip=['code'], escape_misc=True) == r'\*foo\* \<b\>'
assert md('<kbd>*foo*</kbd>', strip=['kbd']) == r'\*foo\*'
assert md('<samp>*foo*</samp>', convert=['b']) == r'\*foo\*'
assert md('<pre>&lt;script&gt;</pre>', convert=['p'], escape_misc=True) == r'\<script\>'
assert md('<code>foo <b>bar</b></code>', strip=['code']) == 'foo **bar**'
assert md('<pre><code>*foo*</code></pre>', strip=['pre']) == '`*foo*`'


def test_strip_document():
assert markdownify("<p>Hello</p>") == "Hello" # test default of STRIP
assert markdownify("<p>Hello</p>", strip_document=LSTRIP) == "Hello\n\n"
Expand Down
Loading