Skip to content

Commit 005c481

Browse files
cvxluoclaude
andauthored
fix(api-docs): strip empty HTML comments from markdown exports (#17992)
Remove extra artifacts in the markdown version of the API docs. We were inserting extra comment markers (`<!-- -->`) and spaces (`&#x20`) within the API docs. Before: ``` * `status`*&#x20;<!-- -->(<!-- -->string<!-- -->)* ``` After: ``` * `status` *(string)* ``` <!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR *Tell us what you're changing and why. If your PR **resolves an issue**, please link it so it closes automatically.* ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [x] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9c6cc55 commit 005c481

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
@@ -89,7 +89,7 @@ function applyKeywordDefaults(markdown) {
8989
const DOCS_ORIGIN = process.env.NEXT_PUBLIC_DEVELOPER_DOCS
9090
? 'https://develop.sentry.dev'
9191
: 'https://docs.sentry.io';
92-
const CACHE_VERSION = 9;
92+
const CACHE_VERSION = 10;
9393
const CACHE_COMPRESS_LEVEL = 4;
9494
const R2_BUCKET = process.env.NEXT_PUBLIC_DEVELOPER_DOCS
9595
? 'sentry-develop-docs'
@@ -1066,6 +1066,12 @@ async function genMDFromHTML(source, {cacheDir, noCache, usedCacheFiles}) {
10661066
.use(rehypeExpandCodeTabs)
10671067
.use(rehypeRemark, {
10681068
document: false,
1069+
// Drop React's empty `<!-- -->` text-node separators, which otherwise leak into the
1070+
// markdown on component-rendered pages like the API docs. Comments dispatch by node
1071+
// type, so this must live in nodeHandlers rather than handlers.
1072+
nodeHandlers: {
1073+
comment() {},
1074+
},
10691075
handlers: {
10701076
// HACK: Extract the canonical URL during parsing
10711077
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)