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
5 changes: 5 additions & 0 deletions markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ def convert_code(self, el, text, parent_tags):
if not text:
return ''

# A line break would let the next line start a new block (heading,
# blockquote, HTML block) before the code span is closed. CommonMark
# renders line endings inside code spans as spaces anyway.
text = text.replace('\n', ' ')

# Find the maximum number of consecutive backticks in the text, then
# delimit the code span with one more backtick than that
max_backticks = max((len(match) for match in re.findall(re_backtick_runs, text)), default=0)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_code_with_tricky_content():
assert md('<code>></code>') == "`>`"
assert md('<code>/home/</code><b>username</b>') == "`/home/`**username**"
assert md('First line <code>blah blah<br />blah blah</code> second line') \
== "First line `blah blah \nblah blah` second line"
== "First line `blah blah blah blah` second line"


def test_special_tags():
Expand Down
3 changes: 3 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def test_code():
assert md('foo<code>`bar`</code>baz') == 'foo`` `bar` ``baz'
assert md('foo<code>``bar``</code>baz') == 'foo``` ``bar`` ```baz'
assert md('foo<code> `bar` </code>baz') == 'foo `` `bar` `` baz'
assert md('<code>foo\n# bar</code>') == '`foo # bar`'
assert md('<kbd>foo\n&lt;script&gt;</kbd>') == '`foo <script>`'
assert md('<samp>foo\n&gt; bar</samp>', escape_misc=True) == '`foo > bar`'


def test_dl():
Expand Down