@@ -50,16 +50,27 @@ function createApiPage(pluginId, readme, pkgJson) {
50
50
const sidebarLabel = toTitleCase ( pluginId ) ;
51
51
52
52
/**
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.
58
61
*/
59
- readme = readme . replaceAll ( / < ! - - .* - - > / g, '' ) . replace ( / < c o d e > ( .* ?) < \/ c o d e > / 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 ( / < c o d e > ( .* ?) < \/ c o d e > / g, ( _match , p1 ) => {
67
+ // Replace { with \{
68
+ return `<code>${ p1 . replace ( / { / g, '\\{' ) } </code>` ;
69
+ } )
70
+ // Convert {@link URL|Text } to [Text](URL)
71
+ . replace ( / \{ @ l i n k \s + ( [ ^ \s | } ] + ) \| ( [ ^ } ] + ) \} / g, '[$2]($1)' )
72
+ // Convert {@link URL } to [URL](URL)
73
+ . replace ( / \{ @ l i n k \s + ( [ ^ } ] + ) \} / g, '[$1]($1)' ) ;
63
74
64
75
return `
65
76
---
0 commit comments