Skip to content

Fix trailing-attr detection when prose contains quotes#24

Open
PiotrCzapla wants to merge 1 commit into
mainfrom
fix-trailing-attr-quotes
Open

Fix trailing-attr detection when prose contains quotes#24
PiotrCzapla wants to merge 1 commit into
mainfrom
fix-trailing-attr-quotes

Conversation

@PiotrCzapla

@PiotrCzapla PiotrCzapla commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The ' or " in headers were breaking trailing attributes {k="v"}
So # Alpha's beta {k="v"} was rendered sa <h1>Alpha's beta {k="v"}</h1>
This pr fixes the issue #23. Here I've run the edge cases before and after the pr: https://share.solveit.pub/d/9c078ad0441301956d58171fece9c4ac

I haven't had time to understand how the state machine in mdhtml works so I'm leaving the Fable explanation below in case you want to put it in to the fable during review.

Fables explanation `last_attr_open` scanned the whole line treating every `'`/`"` as a string delimiter, so a lone quote in prose (e.g. `# Alpha's beta {k="v"}`) hid or shifted the trailing attr block — headings, setext headings, and table captions all affected.

Quote state now belongs to a candidate block, not the line: each { starts its own candidate parse, and the rightmost candidate whose quote-aware scan closes exactly at the line-final } wins. Quoted braces inside values ({a="x{y"}) still parse — the inner candidate never closes, so the true opener wins. Still one O(n) pass: candidates in the same quote state at the same position share a future, so three rightmost-per-state slots suffice, and a quote char swaps the plain slot with that quote's slot.

Also picked up a pending cargo fmt reflow of nested_nodes in block.rs.

Tests: test_trailing_attrs_with_prose_quotes covers both failure modes, a setext heading, the quoted-brace value, and an early-closing block (red before the fix, green after). Full suite: 869 passed, plus cargo fmt / cargo check / cargo test and gen_docs.py --check clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@PiotrCzapla
PiotrCzapla requested a review from jph00 July 23, 2026 20:37
@PiotrCzapla
PiotrCzapla marked this pull request as ready for review July 23, 2026 20:37
Comment thread src/block.rs
Comment on lines +2407 to +2408
fn nested_nodes(
&self,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fable says that it is done by cargo fmt that we were asked to run by DEV.md. No change in meaning.

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