Skip to content

🐛 Preserve whitespace in parsed-literal directives#1176

Open
deepakganesh78 wants to merge 2 commits into
executablebooks:masterfrom
deepakganesh78:fix-parsed-literal-whitespace
Open

🐛 Preserve whitespace in parsed-literal directives#1176
deepakganesh78 wants to merge 2 commits into
executablebooks:masterfrom
deepakganesh78:fix-parsed-literal-whitespace

Conversation

@deepakganesh78

@deepakganesh78 deepakganesh78 commented Jul 25, 2026

Copy link
Copy Markdown

Summary

  • preserve leading and trailing spaces and tabs while parsed-literal content is processed by MyST's Markdown inline parser
  • scope whitespace preservation to ParsedLiteral, leaving other directives' inline parsing unchanged
  • preserve the original whitespace context used by CommonMark delimiter classification
  • add regressions for cross-line delimiter boundaries, decoded private-use entities, and input containing the complete Unicode private-use range
  • add an unreleased changelog entry

Implementation

ParsedLiteral relies on state.inline_text(), while markdown-it's standard newline rule consumes line-edge whitespace and converts two trailing spaces into a hard break. MyST now installs an opt-in newline rule that is activated only while parsing ParsedLiteral: it emits a soft break without consuming adjacent whitespace. The parser therefore sees the untouched source for delimiter classification, and no sentinel characters or collision-prone substitutions are required.

Validation

  • python -m tox -e py311-sphinx8 (1239 passed, 21 skipped)
  • python -m tox -e py311-sphinx9 (1243 passed, 17 skipped)
  • python -m tox -e ruff-fmt -- --check
  • python -m tox -e ruff-check
  • python -m tox -e mypy
  • direct assertions confirmed foo * \nbar* remains literal text and all U+E000–U+F8FF characters plus decoded / round-trip without collision or exhaustion

Fixes #1016

deepakganesh78 and others added 2 commits July 25, 2026 16:09
Protect line-edge whitespace while Markdown inline markup is parsed, then restore it in the generated text nodes. Add regression coverage for spaces, tabs, trailing whitespace, inline markup, and private-use characters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace private-use sentinels with an opt-in markdown-it newline rule that retains adjacent whitespace without changing delimiter classification. Add regressions for cross-line emphasis, decoded private-use entities, and the full private-use range.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

parsed-literal environment does not respect leading whitespace

1 participant