fix(adoc): resolve empty-text cross-references corrupting walker context#1110
fix(adoc): resolve empty-text cross-references corrupting walker context#1110SudhanshuMatrix wants to merge 1 commit into
Conversation
Fixes a bug where rules with 'scope: heading' stopped matching most section titles in an AsciiDoc file if that file combined explicit block anchors with 'xref:' inline macros having empty link text. During HTML compilation, Asciidoctor resolves empty-text cross-references (e.g., 'xref:target[]' or '<<target>>') using the target heading's title. Since this resolved title text is not present in the raw source paragraph containing the reference, Vale's walker fails to locate the exact phrase and falls back to masking individual words across the rest of the document. This erroneously masks those words at subsequent headings, corrupting their text in the walker context and causing them to be silently skipped. We resolve this by pre-processing the AsciiDoc content inside 'lintADoc' to rewrite empty-text cross-references so that their target text matches the literal target identifier present in the raw source: - 'xref:target[]' -> 'xref:target[target]' - '<<target>>' -> '<<target,target>>'
|
Thanks for the PR and the root-cause writeup. The diagnosis is right: empty AsciiDoc xrefs render to the target heading text, that rendered text is not present in the source paragraph, and Vale’s word-by-word fallback can then mask words in later headings. That is what causes the heading-scoped false negatives. I don’t think we should fix this by rewriting the AsciiDoc before render. I tested a smaller fix in the walker instead: |
Description
This PR fixes a silent false-negative bug where rules carrying
scope: headingstop matching section titles in an AsciiDoc file if that file combines explicit block anchors withxref:inline macros (having empty link text).Fixes #1109
Root Cause
xref:id[]or<<id>>) using the target heading's title."first","heading","lowercase") anywhere it can find them in the remaining document context."second heading lowercase"becomes"second @@@@@@@ @@@@@@@@@").Proposed Changes
We intercept the AsciiDoc content inside
lintADocininternal/lint/adoc.gobefore it is passed to Asciidoctor, and rewrite empty-text references:xref:target[]->xref:target[target]<<target>>-><<target,target>>This ensures that the text rendered in the HTML tag is the literal target identifier (e.g.
#introorintro), which is present in the raw source code of the paragraph. Vale's walker successfully matches and masks it within the paragraph block, leaving subsequent headings untouched.How to Test and Verify
repro.adoc):