Skip to content

fix(lint): treat an HTML comment as a text boundary outside inline elements - #1140

Merged
jdkato merged 2 commits into
vale-cli:v3from
VXNCXNX:fix/comment-token-inline-boundary
Aug 14, 2026
Merged

fix(lint): treat an HTML comment as a text boundary outside inline elements#1140
jdkato merged 2 commits into
vale-cli:v3from
VXNCXNX:fix/comment-token-inline-boundary

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

An HTML comment between two words causes a false spelling alert:

$ cat test.md
on <!-- TODO --> a
sonata

$ vale test.md
test.md:2:2  error  Did you really mean 'ona'?  Vale.Spelling

Removing the comment yields no alerts.

lintHTMLTokens sets closedInline in the EndTagToken branch and clears it in StartTagToken, but a CommentToken leaves it untouched. Its consumer is clean(), whose whitespace decision is (closedInline && spaced) || (!closedInline && inline && !starter). After a comment both flags are stale-false, so neither arm fires, the following text loses its leading space, and on + a fuse into ona.

Setting closedInline on a comment only fixes the outer case: a comment right after an inline opening tag is not a closed boundary, and asserting one there disables the #1052 padding. That loses real alerts and invents words — A sona<em><!--c-->ta</em> fuses to sonata, so the genuine sona alert disappears.

So the flag is set only when no inline element is open. Inside one, the opening tag remains the boundary and its padding is preserved.

Fixes #882

Verification

Built before/after binaries and compared:

input before after
on <!-- TODO --> a / sonata 2:2 'ona' no alert
A sona<em><!--c-->ta</em> here. 1:3 'sona' 1:3 'sona'
A sona<b><!-- c --></b>ta here. unchanged unchanged
in <code><!--c-->x</code> for unchanged unchanged
word<!--c-->s stays words stays words
A <!-- c --> sona no alert (fused to Asona) 1:14 'sona'

The last row is a second bug the same change fixes: text after a comment at the start of a fragment was being fused to the preceding word.

go build ./... and go test ./... pass. The regression case is in testdata/e2e/comments.yaml alongside the existing #1001 comment case, and it fails without the fix.

Note lintHTMLTokens is shared across html/md/adoc/rst/org/dita/xml, so this affects all of them; I checked the .html path behaves the same.

…ements

An HTML comment left closedInline untouched, so clean() hit neither arm of
its whitespace rule and the following text lost its leading space. 'on
<!-- TODO --> a' fused to 'ona' and raised a false spelling alert.

Set closedInline on a comment only when no inline element is open. Inside
an open inline element the opening tag is still the boundary, so its
padding (vale-cli#1052) is preserved.

Fixes vale-cli#882
The fixture already covered a comment inside an open <em>, but the case
still asserted no output, so the regression it guards against would not
have failed the suite.
@jdkato
jdkato merged commit e587329 into vale-cli:v3 Aug 14, 2026
@jdkato

jdkato commented Aug 14, 2026

Copy link
Copy Markdown
Member

Thanks!

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.

Comments in markdown trigger erroneous spelling error

2 participants