Skip to content

fix(utils): leave HTML comments out of text content - #621

Open
aliassar wants to merge 1 commit into
comarkdown:mainfrom
aliassar:fix-comment-text-leak
Open

aliassar wants to merge 1 commit into
comarkdown:mainfrom
aliassar:fix-comment-text-leak

Conversation

@aliassar

@aliassar aliassar commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

textContent() and the text walkers in the toc and title-description plugins now skip comment nodes, so an inline <!-- ... --> no longer ends up in heading ids, toc link text, meta.title or meta.description. The plugins keep their own walkers, because they also drop the separate heading-links link and textContent() doesn't, so each one gets the same node[0] === null check instead.

Why

Inline comments have been comment nodes since #401 and stay hidden, but their text still leaked into anything built from text content, and #409 says heading slugs should come from visible text only. That puts things like internal TODOs into public anchors and page titles. Headings with an inline comment get a new id (install-todo-link-guide becomes install-guide), and text around a comment keeps its spaces (Install guide), the same as around an image.

Checks: pnpm run lint, pnpm run typecheck, the comark, html, ansi, vue and React server tests, and the bundle snapshot (unchanged). The React/Svelte browser tests didn't run here because Chromium isn't installed.

Repro:

import { parseMarkdown } from 'comark'
import toc from 'comark/plugins/toc'
import titleDescription from 'comark/plugins/title-description'

const tree = await parseMarkdown('# Install <!-- TODO: link --> guide\n\nRun it <!-- internal --> now.\n\n## Usage <!-- v2 -->\n', {
  plugins: [toc(), titleDescription()],
})
// before: h1 id "install-todo-link-guide", meta.title "Install  TODO: link  guide",
//         meta.description "Run it  internal  now.", toc text "Usage  v2 "
// after:  h1 id "install-guide", meta.title "Install  guide",
//         meta.description "Run it  now.", toc text "Usage "

Read this PR faster    Follow each request

Summary by CodeRabbit

  • Bug Fixes
    • HTML comments are now excluded from extracted plain text, heading IDs, table-of-contents labels, titles, and descriptions. Text surrounding comments remains intact.
  • Documentation
    • Clarified that comments do not contribute to the plain text returned by text extraction.

Inline comments are comment nodes, but `textContent()` and the text
walkers in the `toc` and `title-description` plugins still collected
their body. The comment text ended up in heading ids, toc link text,
`meta.title` and `meta.description`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aliassar
aliassar requested a review from farnabaz as a code owner November 19, 2026 21:08
@coldtea-pr-lens

coldtea-pr-lens Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Architecture

Walkthrough of Exclude HTML comment nodes from text extraction, in three steps

Read this PR faster


Data flow

Data flow diagram for comarkdown/comark at 5fc3b50

Follow each request


Review

✨ Nothing flagged · reviewed 5fc3b50


Tip

The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change

🪧 More tips
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture… row. Drawing still runs as before
  • Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing pull requests on its own. Comment @pr-lens draw on a pull request when you want that one drawn
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • After a push, tick Redraw to draw the latest commit
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion
  • Set github.description: false in .github/pr-lens.yml to stop PR Lens adding buttons to your PR descriptions

Thanks for using PR Lens! It's free for OSS. If it helped, a star helps other teams find it.  Star PR Lens on GitHub

@github-actions

Copy link
Copy Markdown
Contributor

Documentation previews

Previews are disabled for pull requests from forks.
A maintainer can add the preview:enabled label to enable them.

@vercel

vercel Bot commented Nov 19, 2026

Copy link
Copy Markdown

@aliassar is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Text extraction now omits HTML comment content. Title, description, heading ID, and table-of-contents text extraction also exclude comments.

Changes: Comment text exclusion

Layer / File(s) Summary
Exclude comments from extracted text
packages/comark/src/utils/index.ts, packages/comark/src/plugins/title-description.ts, packages/comark/src/plugins/toc.ts, packages/comark/test/text-content.test.ts, packages/comark/test/heading-ids.test.ts, packages/comark/test/plugins/toc.test.ts, packages/comark/test/title-description.test.ts, docs/content/1.getting-started/2.document-model.md
collectText and heading text extraction omit comment nodes. Tests cover text content, heading IDs, table-of-contents links, titles, and descriptions. Documentation states that textContent() excludes comments.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: atinux

Merge Risk: Minimal · up to 5fc3b

Comment text in headings and paragraphs no longer appears in heading IDs, TOC links, titles, descriptions or extracted text. No concrete regression was found, and the change is covered by tests and is easy to revert.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(utils): leave HTML comments out of text content" matches the main change. The PR makes textContent() and the toc and title-description plugin walkers skip comment nodes (node[0] === nul…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(utils): leave HTML comments out of text content" matches the main change. The PR makes textContent() and the toc and title-description plugin walkers skip comment nodes (node[0] === null), so comment text no longer leaks into heading IDs, TOC link text, meta.title, or meta.description. The title is specific and concise, and it follows a conventional commit style.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: debd67d7-620c-460e-a9b5-79cb5e61b486
Commits

Reviewing files that changed from the base of the PR and between 74ba41b and 5fc3b50.

Files selected for processing: 8

  • docs/content/1.getting-started/2.document-model.md
  • packages/comark/src/plugins/title-description.ts
  • packages/comark/src/plugins/toc.ts
  • packages/comark/src/utils/index.ts
  • packages/comark/test/heading-ids.test.ts
  • packages/comark/test/plugins/toc.test.ts
  • packages/comark/test/text-content.test.ts
  • packages/comark/test/title-description.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@621

@comark/angular

npm i https://pkg.pr.new/@comark/angular@621

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@621

@comark/html

npm i https://pkg.pr.new/@comark/html@621

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@621

@comark/react

npm i https://pkg.pr.new/@comark/react@621

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@621

@comark/vue

npm i https://pkg.pr.new/@comark/vue@621

commit: 5fc3b50

@codspeed

codspeed Bot commented Nov 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 44 untouched benchmarks


Comparing aliassar:fix-comment-text-leak (5fc3b50) with main (74ba41b)

Open in CodSpeed

This branch has not been deployed

No deployments
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