Skip to content

fix: detect raw end tags and comments inside code blocks - #45

Merged
malav2110 merged 1 commit into
malav2110:mainfrom
Aaqibhafeezkhan:fix/issue-40-code-block-raw-markup
Nov 21, 2026
Merged

malav2110 merged 1 commit into
malav2110:mainfrom
Aaqibhafeezkhan:fix/issue-40-code-block-raw-markup

Conversation

@Aaqibhafeezkhan

@Aaqibhafeezkhan Aaqibhafeezkhan commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Detect raw HTML comments and unmatched closing tags inside code blocks, including bare <pre> blocks.

Changes

  • Detect unexpected elements, HTML comments and unmatched raw end tags.
  • Use parse5 source locations to distinguish matched tags from raw tags.
  • Exclude comments and script/style contents from the source scan.
  • Add regression fixtures for raw closing tags, comments and bare <pre> blocks.
  • Add passing fixtures for valid comments and script contents.
  • Keep the generated validator bundle synchronized.
  • Preserve the existing validation workflow.

Closes #40

@Aaqibhafeezkhan Aaqibhafeezkhan left a comment

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.

Self-review:

  • Extended code-escaped to detect unexpected HTML comments.
  • Added detection for malformed closing tags using parse5 parser errors and source offsets.
  • Preserved the existing allowed syntax-highlight spans.
  • Added regression fixtures for the reported edge cases.
  • Updated validation documentation.
  • Verify the generated validator bundle is updated.
  • Run the build, type checks, and complete test suite.

@Aaqibhafeezkhan
Aaqibhafeezkhan force-pushed the fix/issue-40-code-block-raw-markup branch from bd94cb0 to b876470 Compare November 16, 2026 06:01
@malav2110

Copy link
Copy Markdown
Owner

Hey @Aaqibhafeezkhan , Thank you for raising the PR. I will review and get back to you.

@Aaqibhafeezkhan
Aaqibhafeezkhan force-pushed the fix/issue-40-code-block-raw-markup branch 2 times, most recently from d89862e to 4101b69 Compare November 20, 2026 00:34

@malav2110 malav2110 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for picking this up, @Aaqibhafeezkhan. A raw comment and a raw </div> in a code block now fail the check, and every sample still passes.

Two things block it. The workflow changes need to come out. And the </pre><script> case from #40 still passes in a bare <pre>, with no fixture that shows it. The rest are non-blocking.

I also need to correct my note on the issue: onParseError was the wrong pointer. My comment on src/validate-output.ts lines 278-301 explains why.

Comment thread .github/workflows/checks.yml Resolved
Comment thread src/validate-output.ts Resolved
Comment thread src/validate-output.ts Resolved
Comment thread src/validate-output.ts Resolved
@Aaqibhafeezkhan
Aaqibhafeezkhan force-pushed the fix/issue-40-code-block-raw-markup branch from 121835a to 018426b Compare November 21, 2026 00:39

@malav2110 malav2110 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, @Aaqibhafeezkhan. This covers everything from my last review. The workflow is back to the original step, the bare <pre> case and the other three now fail, and every sample still passes.

A couple of small things remain before I merge:

  • The PR description now describes a different change, a label check that closes #137. Could you put back a description of this change with "Closes #40", so the issue closes on merge?
  • An off-by-one in the new comment range, inline below.

Once those are in, I don't need another round.

Comment thread src/validate-output.ts Outdated
for (const comment of filter(isComment, document.children, true)) {
const start = comment.startIndex ?? -1;
const end = comment.endIndex ?? start;
ignoredRanges.push({ start, end: end + 1 });

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

suggestion (non-blocking): The new end-tag search skips an end tag written right after a comment.

The tree adapter already sets endIndex to parse5's endOffset, which points one character past the comment. Adding 1 pushes the range onto the < of the next tag, so <p>x</p><!-- note --></div> passes. Inside a code block the comment itself still fails the check, so this only hides an end tag outside one. No sample page has this pattern today.

A fail page with <!-- note --></div> would cover the fix. Separately, no test or sample page touches the comment and script exclusions yet. A pass page with <!-- </div> --> and a "</div>" string inside a <script> would cover them.

Suggested change
ignoredRanges.push({ start, end: end + 1 });
ignoredRanges.push({ start, end });

Signed-off-by: Aaqibhafeez Khan <githubaaqibhafeezkhan@gmail.com>
@Aaqibhafeezkhan
Aaqibhafeezkhan force-pushed the fix/issue-40-code-block-raw-markup branch from b74f05c to 93b85db Compare November 21, 2026 21:30

@malav2110 malav2110 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you @Aaqibhafeezkhan . Merging in.

@malav2110
malav2110 merged commit a3f512b into malav2110:main Nov 21, 2026
5 checks passed
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.

Catch raw end tags and comments inside code blocks

2 participants