Skip to content

DOC-6939 Stop publishing HTML-commented content to the AI outputs - #3758

Merged
andy-stark-redis merged 1 commit into
mainfrom
DOC-6939-html-comments
Aug 6, 2026
Merged

DOC-6939 Stop publishing HTML-commented content to the AI outputs#3758
andy-stark-redis merged 1 commit into
mainfrom
DOC-6939-html-comments

Conversation

@andy-stark-redis

@andy-stark-redis andy-stark-redis commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Stops content inside HTML comments reaching the JSON feed and the per-page Markdown — item D4 of DOC-6939.

The defect

Hugo runs with unsafe = true, so an HTML comment passes straight through to the rendered page. It's invisible to readers, which is exactly how authors park prose that shouldn't be published yet. Nothing in the AI output path knew that, so commented text was being treated as publishable content.

We were publishing to AI consumers exactly what we withhold from readers. That's worse than a formatting defect — an assistant can cite a feature as documented when we have deliberately not documented it.

The case that surfaced it is develop/clients/observability, where a comment holds an entire "Tracing overview" section, kept because the explanation is good but the clients don't support tracing yet:

Artifact Before After
Rendered page Hidden inside an HTML comment ✓ unchanged ✓
sections[] in the feed A real section, 1,610 chars of prose gone
Per-page Markdown Present gone
Metadata TOC Present, pointing at a non-existent anchor gone

Across the corpus, 56 files carry HTML comments totalling about 22,000 characters. Only 2 of those comments contain a heading, which is why just one showed up in an anchor-parity check — the other 54 leak their prose into whatever section encloses them, invisible to any id-based metric.

The fix, and why it's line-anchored

A line-anchored strip in process-markdown-content.html (the choke point feeding both the JSON content field and the Markdown output) and in toc-from-markdown.html (which reads .RawContent directly).

The open delimiter must be at the start of a line, and that's load-bearing. HTML comments legitimately appear inside code examples — the Lettuce pages carry a Maven snippet with </version> <!-- Check for the latest version on Maven Central --> mid-line, and stripping that damages a sample a reader sees. Column-0 is what separates an author's parked block from a comment inside a code sample:

Pattern Removes Matches inside a fenced code block
Unanchored (?s)<!--.*?--> 214 comments / 24,560 chars 9
Line-anchored (?ms)^<!--.*?--> 48 comments / 19,232 chars 0

Both the literal and entity-escaped forms are matched, because .RawContent arrives escaped in some contexts.

Verification

Built before and after, comparing every page's content field:

  • 5,706 pages byte-identical
  • 27 shrank, and every one of the 27 is explained by having a line-anchored comment
  • 0 grew, 0 changed pages unexplained
  • Zero line-anchored comments survive into sections[] or the .md output
  • Duplicate section ids 0, duplicate example ids 0, content_hash verifies 5,687/5,687

What a reviewer should focus on

  • The rendered site is untouched. process-markdown-content.html feeds only the JSON and Markdown output formats, not the HTML, so nothing readers see changes.
  • 27 pages lose content from their AI outputs. That's the intent, but it is content removal, so the byte-diff above is the thing to trust.
  • If the anchoring is ever relaxed, it will start eating comments out of code samples at 9 known sites.

Deliberately not fixed in the content

The comment on observability.md is a legitimate authoring choice — good prose held back until the clients catch up. Removing it would have fixed one page and left 55. The defect is that our pipeline treated invisible content as publishable.

Not in this PR

  • Inline comments, about 2,800 characters, still reach the outputs. Almost all of it is part of a code sample and belongs there.
  • A block comment written at column 0 inside a fenced code block would still be stripped. None exists today.

Relationship to #3757

Independent. #3757 (D3 + C7) changes how titles and ids are derived; this changes what content is considered publishable. Both edit toc-from-markdown.html but in different regions — line ~27 here against lines 47+ there — so they merge cleanly in either order.

🤖 Generated with Claude Code


Note

Medium Risk
Intentional content removal from JSON/Markdown for ~27 pages; wrong regex anchoring could damage code samples, but rendered site HTML is out of scope.

Overview
Stops author-parked HTML comment blocks from being treated as publishable content in the JSON feed, per-page Markdown, and metadata TOC—while leaving the normal Hugo HTML site unchanged.

process-markdown-content.html now removes line-anchored <!-- ... --> blocks (and entity-escaped equivalents) before embeds, shortcodes, and other transforms, so sections[] / body text no longer include prose that readers never see (e.g. a commented-out “Tracing overview” on observability). The pattern requires the opening delimiter at column 0 so mid-line comments inside code samples (Maven snippets, etc.) are not stripped.

toc-from-markdown.html applies the same line-anchored strip after fenced code blocks are removed, so commented headings do not appear as TOC entries with dead anchors.

Scope: ~27 AI-facing pages shrink by design; inline comments and rendered HTML are unaffected. Relaxing line anchoring would risk stripping comments inside fenced code at known sites.

Reviewed by Cursor Bugbot for commit 2c4e608. Bugbot is set up for automated code reviews on this repo. Configure here.

Hugo runs with unsafe = true, so an HTML comment passes through to the rendered
page and is invisible to readers, which is how authors park prose that should not
be published yet. Nothing in the AI output path knew that, so commented text
reached the JSON feed as real section content and the Markdown output as real body
text. We were publishing to AI consumers exactly what we withhold from readers,
which is worse than a formatting defect: an assistant can cite a feature as
documented when we have deliberately not documented it.

The case that surfaced it was develop/clients/observability, where a comment holds
an entire "Tracing overview" section, kept because the explanation is good but the
clients do not support tracing yet. The feed published it as a section with 1,610
characters of prose and the table of contents listed it, pointing at an anchor that
does not exist because Hugo renders no heading for commented-out text. Across the
corpus, 56 files carry HTML comments totalling about 22,000 characters.

The important thing to know before touching the pattern: HTML comments legitimately
appear inside code examples. A Maven snippet on the Lettuce pages carries
"</version> <!-- Check for the latest version on Maven Central -->" mid-line, and
stripping that would damage the sample a reader sees. Requiring the open delimiter
to sit at the start of a line is what separates an author's parked block from a
comment inside a code sample. Measured over the whole corpus, the line-anchored form
removes 48 comments and about 19,200 characters and never matches inside a fenced
code block, where the unanchored form matches 9 times.

I nearly rejected the right pattern on a bad measurement, which is worth recording.
My first safety test asked whether a match overlapped a fenced code block, and
reported 8 overlaps even for the line-anchored form. Those 8 were comments that
*contain* a code block, which is exactly what should be removed -- the opposite of
the dangerous case, a comment sitting *inside* a code block. Asking the right
question, whether the match is fully contained by a code span, gives 0 for the
anchored form and 9 for the unanchored one.

Verified by building before and after and comparing every page's content field:
5,706 pages byte-identical, 27 shrank, every one of the 27 explained by having a
line-anchored comment, and none grew. No line-anchored comment now survives into
either sections[] or the Markdown output. Duplicate section and example ids stay at
zero and content_hash still verifies for all 5,687 content pages.

Deliberately not fixed by editing the content. The comment is a legitimate
authoring choice, and removing it would have fixed one page and left 55.

Learned: HTML comments legitimately appear inside code examples, so comment stripping has to be line-anchored -- an unanchored pattern damages a Maven snippet on the Lettuce pages and 8 other sites
Learned: a safety check asking whether a match "overlaps" a code block conflates two opposite situations, a comment that contains a code block against a comment inside one, and it wrongly condemned the correct pattern until the test asked about containment instead
Constraint: the comment strip must keep its line-anchored open delimiter in both places, or it starts eating comments out of code samples
Constraint: the strip is implemented twice, in layouts/partials/process-markdown-content.html and layouts/partials/toc-from-markdown.html, and must be changed together
Gaps: inline comments, about 2,800 characters, still reach the outputs -- almost all of it is part of a code sample and belongs there; and a block comment written at column 0 inside a fenced code block would still be stripped, though none exists today
Ticket: DOC-6939
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

DOC-6939

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🧠 Redis Memory

Found 5 related items from repository history:

  • Commit
  • Commit
  • Commit
  • Commit
  • Commit

Memory updated at 2c4e608

@andy-stark-redis
andy-stark-redis requested a review from a team August 6, 2026 12:56
@andy-stark-redis andy-stark-redis self-assigned this Aug 6, 2026
@andy-stark-redis andy-stark-redis added infrastructure AI-friendliness Features that help AI tools understand and use the doc pages more easily. labels Aug 6, 2026

@dwdougherty dwdougherty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

@andy-stark-redis
andy-stark-redis merged commit e017d7a into main Aug 6, 2026
88 checks passed
@andy-stark-redis
andy-stark-redis deleted the DOC-6939-html-comments branch August 6, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-friendliness Features that help AI tools understand and use the doc pages more easily. infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants