Skip to content

馃悰 Fix code span padding around non-space whitespace - #448

Open
hulkbig wants to merge 1 commit into
executablebooks:masterfrom
hulkbig:fix/codespan-ascii-space-padding-20261012
Open

hulkbig wants to merge 1 commit into
executablebooks:masterfrom
hulkbig:fix/codespan-ascii-space-padding-20261012

Conversation

@hulkbig

@hulkbig hulkbig commented Oct 12, 2026

Copy link
Copy Markdown

Summary

Use strip(" ") when checking whether a code span consists entirely of spaces. Python's argumentless strip() also removes tabs and other Unicode whitespace, which incorrectly prevents removal of the surrounding U+0020 padding.

This follows CommonMark 0.31.2 搂6.1: normalize line endings, then remove one space from each end unless the content consists entirely of spaces.

Reproduction

from markdown_it import MarkdownIt

MarkdownIt("commonmark").renderInline("` \t `")
# Before: "<code> \t </code>"
# After:  "<code>\t</code>"

Related #438, specifically its code span padding example. This change is limited to padding normalization; the backtick lookahead behavior discussed in #439 is unchanged.

Tests

  • Add 52 parameterized cases covering tabs, NBSP and other whitespace, all-space content, one-sided padding, multiple spaces, line-ending normalization, and one- or two-backtick delimiters. Check rendered HTML and parsed code-token content.
  • Before the fix: 28 new cases fail and 24 pass. After the fix: all 52 pass.
  • tox -e py310,py311,py312,py313: 1,084 tests pass on each CPython version.
  • pre-commit run --all-files: passes, including Ruff, formatting, and mypy.

AI assistance

AI assistance was used for diagnosis, implementation, regression tests, validation, and PR preparation. A separate AI agent independently reviewed the change.

@hulkbig
hulkbig marked this pull request as ready for review October 12, 2026 02:23

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.

1 participant