Skip to content

Commit 9d48e59

Browse files
cvxluoclaude
andcommitted
fix(md-exports): clean up artifacts in API docs markdown exports
Two sources of noise leaked into the API .md exports, e.g. `*&#x20;<!-- -->(<!-- -->string<!-- -->)*`: - React inserts empty `<!-- -->` separator comments between adjacent text nodes in server-rendered output (common on component-rendered pages like the API docs). Drop comment nodes in the HTML->markdown pipeline; comments dispatch by node type, so this lives in nodeHandlers, not handlers. - The parameter type was wrapped in an <em> with a leading space inside it, which remark encoded as `&#x20;`. Move the space outside the <em> so it serializes as a normal space. Also bump CACHE_VERSION, since cached entries are keyed on input HTML (not on this script) and would otherwise serve stale output after the logic change. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f8426b0 commit 9d48e59

3 files changed

Lines changed: 31 additions & 3 deletions

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+
});

src/components/apiPage/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ function Params({params}) {
2020
<Fragment key={param.name}>
2121
<dt>
2222
<div>
23-
<code data-index>{param.name}</code>
23+
<code data-index>{param.name}</code>{' '}
2424
{!!param.schema?.type && (
2525
<em>
26-
{' '}
2726
({param.schema.type}
2827
{param.schema.items && `(${param.schema.items.type})`})
2928
</em>

0 commit comments

Comments
 (0)