Skip to content

🐛 FIX: Drop continuation-line indentation inside code spans - #476

Open
bardrop wants to merge 1 commit into
executablebooks:masterfrom
bardrop-oss:fix-code-span-continuation-indent
Open

bardrop wants to merge 1 commit into
executablebooks:masterfrom
bardrop-oss:fix-code-span-continuation-indent

Conversation

@bardrop

@bardrop bardrop commented Nov 17, 2026

Copy link
Copy Markdown

Fixes #475.

Leading spaces or tabs on paragraph continuation lines are not part of the paragraph's raw content (CommonMark 4.8, example 223). The newline rule already skips them for normal text, but the backticks rule takes the source as is and only turns \n into a space, so the indent ends up inside <code>:

>>> MarkdownIt("commonmark").render("`a\n    b`\n")
'<p><code>a     b</code></p>\n'   # before
'<p><code>a b</code></p>\n'       # after, same as commonmark.js 0.31.2

The fix replaces \n plus any following spaces/tabs with one space. Trailing spaces before the line ending are kept, as commonmark.js does (`a \n b` → <code>a b</code>).

I found this by running markdown-it-py and commonmark.js 0.31.2 on ~30,000 generated inputs. markdown-it 15.0.3 gives the same output as markdown-it-py today.

Tests: 4 new cases in tests/test_port/fixtures/issue-fixes.md (spaces, tab, list item with extra indent, trailing spaces kept); all 4 fail without the change. pytest tests: 1194 passed; pre-commit (ruff, ruff-format, mypy) clean. On the same 30,000 inputs, 52 more now match commonmark.js and none newly differ.

Leading spaces or tabs of paragraph continuation lines are not part of the
paragraph's raw content (CommonMark 4.8), but the backticks rule only
turned the line ending into a space, so ``a\n    b`` gave
<code>a     b</code> instead of <code>a b</code> (commonmark.js).

Fixes executablebooks#475

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code span keeps the indentation of a continuation line

1 participant