Skip to content

Commit 394a5f4

Browse files
cvxluoclaude
andcommitted
fix(md-exports): strip empty HTML comments from markdown exports
React inserts empty `<!-- -->` separator comments between adjacent text nodes in server-rendered output. On component-rendered pages like the API docs, this littered the `.md` exports with artifacts such as `(<!-- -->string<!-- -->)` around parameter types. Drop comment nodes in the HTML-to-markdown pipeline. Comments are dispatched by node type in hast-util-to-mdast, so the override goes in `nodeHandlers` rather than `handlers` (where it would be silently ignored). The field type text survives the strip, so `(<!-- -->string<!-- -->)` becomes `(string)`. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f8426b0 commit 394a5f4

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

scripts/generate-md-exports.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {rehypeExpandCodeTabs} from './rehype-expand-code-tabs.mjs';
3232
const DOCS_ORIGIN = process.env.NEXT_PUBLIC_DEVELOPER_DOCS
3333
? 'https://develop.sentry.dev'
3434
: 'https://docs.sentry.io';
35-
const CACHE_VERSION = 9;
35+
const CACHE_VERSION = 10;
3636
const CACHE_COMPRESS_LEVEL = 4;
3737
const R2_BUCKET = process.env.NEXT_PUBLIC_DEVELOPER_DOCS
3838
? 'sentry-develop-docs'
@@ -1009,6 +1009,12 @@ async function genMDFromHTML(source, {cacheDir, noCache, usedCacheFiles}) {
10091009
.use(rehypeExpandCodeTabs)
10101010
.use(rehypeRemark, {
10111011
document: false,
1012+
// Drop React's empty `<!-- -->` text-node separators, which otherwise leak into the
1013+
// markdown on component-rendered pages like the API docs. Comments dispatch by node
1014+
// type, so this must live in nodeHandlers rather than handlers.
1015+
nodeHandlers: {
1016+
comment() {},
1017+
},
10121018
handlers: {
10131019
// HACK: Extract the canonical URL during parsing
10141020
link: (_state, node) => {

scripts/generate-md-exports.test.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ function htmlToMarkdown(html) {
1515
.use(rehypeExpandCodeTabs)
1616
.use(rehypeRemark, {
1717
document: false,
18+
nodeHandlers: {
19+
comment() {},
20+
},
1821
handlers: {
1922
button() {},
2023
},
@@ -306,3 +309,23 @@ describe('rehypeExpandCodeTabs', () => {
306309
});
307310
});
308311
});
312+
313+
describe('comment stripping', () => {
314+
it('drops React text-node separator comments emitted on component-rendered pages', () => {
315+
const html =
316+
'<p><code>organization_id_or_slug</code><em> (<!-- -->string<!-- -->)</em></p>';
317+
318+
const md = htmlToMarkdown(html);
319+
320+
expect(md).not.toContain('<!--');
321+
expect(md).toContain('string');
322+
});
323+
324+
it('drops standalone HTML comments', () => {
325+
const md = htmlToMarkdown('<p>before<!-- a real comment -->after</p>');
326+
327+
expect(md).not.toContain('<!--');
328+
expect(md).toContain('before');
329+
expect(md).toContain('after');
330+
});
331+
});

0 commit comments

Comments
 (0)