Skip to content

Commit 89ba552

Browse files
authored
chore(script-native): convert JSDoc links to Markdown links (#4099)
1 parent b6c937a commit 89ba552

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

scripts/native.mjs

+20-9
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,27 @@ function createApiPage(pluginId, readme, pkgJson) {
5050
const sidebarLabel = toTitleCase(pluginId);
5151

5252
/**
53-
* - removes JSDoc HTML comments as they break docusauurs
54-
* - The { character is used for opening JavaScript expressions.
55-
* MDX will now fail if what you put inside {expression} that is
56-
* not a valid expression: replace it by escaping it with a backslash.
57-
* Only do this for { characters that are inside <code> blocks.
53+
* Cleanup and transform JSDoc content for compatibility with MDX/Docusaurus:
54+
*
55+
* - Remove HTML comments (`<!-- ... -->`) which are not valid in MDX and will cause parsing errors.
56+
* - Escape `{` characters inside <code> blocks because MDX treats `{}` as JavaScript expressions. Unescaped `{` inside code blocks can cause parsing errors.
57+
* - Convert JSDoc-style {@link URL|Text} and {@link URL} to proper Markdown links:
58+
* - {@link URL|Text} → [Text](URL)
59+
* - {@link URL} → [URL](URL)
60+
* This is necessary because MDX does not understand the JSDoc `@link` syntax, and leaving it unconverted will cause parsing errors.
5861
*/
59-
readme = readme.replaceAll(/<!--.*-->/g, '').replace(/<code>(.*?)<\/code>/g, (_match, p1) => {
60-
// Replace { with \{ inside the matched <code> content
61-
return `<code>${p1.replace(/{/g, '\\{')}</code>`;
62-
});
62+
readme = readme
63+
// Remove HTML comments
64+
.replaceAll(/<!--.*-->/g, '')
65+
// Escape `{` characters inside <code> blocks to avoid Markdown parsing issues
66+
.replace(/<code>(.*?)<\/code>/g, (_match, p1) => {
67+
// Replace { with \{
68+
return `<code>${p1.replace(/{/g, '\\{')}</code>`;
69+
})
70+
// Convert {@link URL|Text} to [Text](URL)
71+
.replace(/\{@link\s+([^\s|}]+)\|([^}]+)\}/g, '[$2]($1)')
72+
// Convert {@link URL} to [URL](URL)
73+
.replace(/\{@link\s+([^}]+)\}/g, '[$1]($1)');
6374

6475
return `
6576
---

0 commit comments

Comments
 (0)