mdformat fails with:
Formatted Markdown renders to different HTML than input Markdown.
when an inline code span contains trailing whitespace inside the backticks.
This makes formatting impossible for otherwise valid Markdown.
This appears to be triggered only when the mdformat-mkdocs plugin is enabled.
Environment
mdformat==1.0.0
mdformat-mkdocs==5.1.4
markdown-it-py==4.0.0
mdit-py-plugins==0.5.0
pre-commit
python 3.13 (also reproducible after clean environment rebuild)
macOS
Minimal reproduction
test.md
Run:
pre-commit run mdformat --files test.md -v
Actual behavior
Error: Could not format
Formatted Markdown renders to different HTML than input Markdown.
Expected behavior
Formatting should succeed (or at least not fail hard).
Trailing whitespace inside inline code spans should not cause HTML instability.
Observations
Works:
Fails:
Removing only the trailing space fixes it.
This suggests the plugin/parser combination produces different HTML before vs after formatting when trailing whitespace exists inside inline code.
Notes
Reproduces consistently after:
So it’s not cache-related.
mdformatfails with:when an inline code span contains trailing whitespace inside the backticks.
This makes formatting impossible for otherwise valid Markdown.
This appears to be triggered only when the
mdformat-mkdocsplugin is enabled.Environment
Minimal reproduction
test.md
Run:
Actual behavior
Expected behavior
Formatting should succeed (or at least not fail hard).
Trailing whitespace inside inline code spans should not cause HTML instability.
Observations
Works:
Fails:
Removing only the trailing space fixes it.
This suggests the plugin/parser combination produces different HTML before vs after formatting when trailing whitespace exists inside inline code.
Notes
Reproduces consistently after:
So it’s not cache-related.