fix: preserve mixed-fence code blocks in doc rendering#22350
Conversation
`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>
There was a problem hiding this comment.
You didn't integrate the suggested changes in #13850 (comment), which is the reason that PR got closed.
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>
I updated to use pulldown-cmark per @lowr's #13850 (comment). Thanks for the pointer. |
|
@ChayimFriedman2 just sending a friendly bump. The v2 pulldown-cmark rewrite from 2026.05.15 has been sitting with CI green; happy to make further changes if anything still looks off, or close this out if you'd prefer to pass on it. |
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.