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
9 changes: 8 additions & 1 deletion markdown_it/rules_inline/backticks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Parse backticks
import re

from .state_inline import StateInline

_NEWLINE_INDENT_RE = re.compile(r"\n[ \t]*")


def _build_last_runs(src: str) -> dict[int, int]:
"""Map each backtick run length to its last position in the source."""
Expand Down Expand Up @@ -56,7 +60,10 @@ def backtick(state: StateInline, silent: bool) -> bool:
if not silent:
token = state.push("code_inline", "code", 0)
token.markup = marker
content = state.src[pos:match_start].replace("\n", " ")
# Line endings become spaces. The leading spaces or tabs of
# each continuation line are not part of the paragraph's raw
# content (CommonMark 4.8), so they are dropped too.
content = _NEWLINE_INDENT_RE.sub(" ", state.src[pos:match_start])
# Strip one space from each side, unless the content is all spaces
if (
content.startswith(" ")
Expand Down
34 changes: 34 additions & 0 deletions tests/test_port/fixtures/issue-fixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,37 @@ para
*a*
</pre>
.

#475 a code span drops the indentation of a continuation line
.
`a
b`
.
<p><code>a b</code></p>
.

#475 same with a tab
.
x `a
b`
.
<p>x <code>a b</code></p>
.

#475 same inside a list item with extra indentation
.
1. x `a
b`
.
<ol>
<li>x <code>a b</code></li>
</ol>
.

#475 trailing spaces before the line ending are kept
.
`a
b`
.
<p><code>a b</code></p>
.