Skip to content

fix: preserve mixed-fence code blocks in doc rendering#22350

Open
MavenRain wants to merge 2 commits into
rust-lang:masterfrom
MavenRain:fix-doc-mixed-fences
Open

fix: preserve mixed-fence code blocks in doc rendering#22350
MavenRain wants to merge 2 commits into
rust-lang:masterfrom
MavenRain:fix-doc-mixed-fences

Conversation

@MavenRain
Copy link
Copy Markdown
Contributor

@MavenRain MavenRain commented May 12, 2026

Resurrects the fix that #13850 attempted in 2023 before being closed for inactivity. format_docs_ was treating ``` and ~~~ as interchangeable fences, so a literal ~~~ line inside a ```-opened block closed the block early (and the mirror case for ```-inside- ~~~). Tracks the opening fence and closes only on a match.

Closes #13815.

  `format_docs_` was toggling `in_code_block` whenever any
  RUSTDOC_FENCES prefix appeared, so a `~~~` line inside a
  ```-opened block would close the block prematurely (and a
  ``` line inside a ~~~-opened block would do the same).
  Track which fence opened the current block in
  `current_fence: Option<&'static str>` and only close on the
  matching fence.

  Closes rust-lang#13815.

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 12, 2026
Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't integrate the suggested changes in #13850 (comment), which is the reason that PR got closed.

View changes since this review

  Use `pulldown-cmark` to delimit fenced code blocks instead of the
  hand-rolled line-prefix matcher.  Per @ChayimFriedman2's review on
  rust-lang#22350 (referencing @lowr's earlier note on
  rust-lang#13850), this brings `format_docs_` in line
  with the full CommonMark spec: variable-length fences, mixed fence
  characters (``` vs ~~~), and fences nested inside other block
  constructs.

  `format_docs_` now collects fenced code block byte ranges via
  `Parser::into_offset_iter()` and transforms only inside those
  ranges (rust-info rewrite, `#`-line stripping, `##`-escape
  unwrapping), leaving the surrounding markdown byte-for-byte.

  Closes rust-lang#13815.

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
@MavenRain
Copy link
Copy Markdown
Contributor Author

You didn't integrate the suggested changes in #13850 (comment), which is the reason that PR got closed.

View changes since this review

I updated to use pulldown-cmark per @lowr's #13850 (comment). Thanks for the pointer. format_docs_ now uses Parser::into_offset_iter() to delimit fenced code blocks per the CommonMark spec, with the existing rust-info rewrite,
#-line stripping, and ##-escape unwrapping preserved. The two mixed-fence regression tests still pass and the existing tests are untouched.

@MavenRain MavenRain requested a review from ChayimFriedman2 May 15, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken markdown for mixing backticks and tildes in code block

3 participants