Skip to content

Commit 4066bc2

Browse files
authored
fix 'platform-specific' heading on js api (#3413)
1 parent 841149b commit 4066bc2

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

packages/js-api-generator/build.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ function pageEventEnd(event: PageEvent<DeclarationReflection>) {
169169
class TauriThemeRenderContext extends MarkdownThemeContext {
170170
constructor(theme: MarkdownTheme, page: MarkdownPageEvent<Reflection>, options: Options) {
171171
super(theme, page, options);
172+
const originalCommentPartial = this.partials.comment;
173+
172174
this.partials = {
173175
...this.partials,
174176
// Formats `@source` to be a single line
@@ -180,6 +182,37 @@ class TauriThemeRenderContext extends MarkdownThemeContext {
180182
const sources = model.sources.map((source) => `${source.url}`);
181183
return label + sources.join(', ');
182184
},
185+
// Remove heading markers from JSDoc comments to prevent accidental markdown headings
186+
comment: function (comment, options) {
187+
const headingStringsToReplace = [
188+
// known to break
189+
'#### Platform-specific',
190+
// just to be sure
191+
'### Platform-specific',
192+
];
193+
194+
if (comment?.summary) {
195+
comment.summary.forEach((line) => {
196+
if (line.kind === 'text' && typeof line.text === 'string') {
197+
headingStringsToReplace.forEach((headingString) => {
198+
line.text = line.text.replace(headingString, headingString.replace(/^#+\s*/, ''));
199+
});
200+
}
201+
});
202+
}
203+
if (comment?.blockTags) {
204+
comment.blockTags.forEach((tag) => {
205+
tag.content.forEach((line) => {
206+
if (line.kind === 'text' && typeof line.text === 'string') {
207+
headingStringsToReplace.forEach((headingString) => {
208+
line.text = line.text.replace(headingString, headingString.replace(/^#+\s*/, ''));
209+
});
210+
}
211+
});
212+
});
213+
}
214+
return originalCommentPartial.call(this, comment, options);
215+
},
183216
};
184217
}
185218

packages/js-api-generator/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"tsm": "^2.3.0",
1616
"typedoc": "0.26.6",
1717
"typedoc-plugin-markdown": "4.2.6",
18-
"typedoc-plugin-mdn-links": "3.2.11"
18+
"typedoc-plugin-mdn-links": "3.2.11",
19+
"typescript": "5.5"
1920
}
2021
}

pnpm-lock.yaml

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)