From 7692f8e1ca34d082dfac83495e639bfd556b6883 Mon Sep 17 00:00:00 2001 From: Emmanuel Evance Date: Wed, 16 Sep 2026 17:06:18 +0300 Subject: [PATCH 1/2] fix broken links --- generate-adaptors/index.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/generate-adaptors/index.js b/generate-adaptors/index.js index cc787abffd9..c8a7b576142 100644 --- a/generate-adaptors/index.js +++ b/generate-adaptors/index.js @@ -108,9 +108,43 @@ function escapeMdx(content) { return parts.join(''); } +// Rewrite bare function references like [http.get](http.get), which JSDoc +// emits for @see/@deprecated tags, into same-page anchors (#http_get). +// Docusaurus otherwise resolves them as relative paths and fails the build. +function fixFunctionLinks(content) { + const anchors = new Set(); + const anchorRegex = /\{#([\w-]+)\}/g; + let match; + while ((match = anchorRegex.exec(content))) { + anchors.add(match[1]); + } + + const codeBlockRegex = /(```[\s\S]*?```|`[^`]*`)/g; + const parts = content.split(codeBlockRegex); + + for (let i = 0; i < parts.length; i++) { + // odd indices are code blocks - leave them alone + if (i % 2 === 1) continue; + + parts[i] = parts[i].replace( + /\[([^\]]+)\]\((?!https?:|\/|#|\.)([A-Za-z_$][\w$]*(?:\.[\w$]+)*)\)/g, + (link, text, target) => { + const id = target.replace(/\./g, '_'); + // only link if the page actually defines that anchor, otherwise drop + // the link and keep the text so we never emit a broken link + return anchors.has(id) ? `[${text}](#${id})` : text; + } + ); + } + + return parts.join(''); +} + function generateJsDoc(a) { // Add line break before tags and escape MDX specials outside code blocks - const docsContent = escapeMdx(JSON.parse(a.docs).replace(/<\/dt>/g, '\n')); + const docsContent = escapeMdx( + fixFunctionLinks(JSON.parse(a.docs).replace(/<\/dt>/g, '\n')) + ); return `--- title: ${a.name}@${a.version} From ad3049ea80647bdb220ab06140dca6ad4bab4271 Mon Sep 17 00:00:00 2001 From: Emmanuel Evance Date: Wed, 16 Sep 2026 17:50:04 +0300 Subject: [PATCH 2/2] add unit test --- generate-adaptors/index.js | 137 ++++++++++++++++++++--------- generate-adaptors/index.test.js | 147 ++++++++++++++++++++++++++++++++ 2 files changed, 246 insertions(+), 38 deletions(-) create mode 100644 generate-adaptors/index.test.js diff --git a/generate-adaptors/index.js b/generate-adaptors/index.js index c8a7b576142..686ef22798b 100644 --- a/generate-adaptors/index.js +++ b/generate-adaptors/index.js @@ -87,65 +87,120 @@ function pushToPaths(name) { }); } -// Escape characters that MDX would parse as JSX outside of code blocks -function escapeMdx(content) { - // Split content by code blocks (both inline ` and multi-line ```) - const codeBlockRegex = /(```[\s\S]*?```|`[^`]*`)/g; - const parts = content.split(codeBlockRegex); - - // Escape only in non-code parts (odd indices are code blocks) - for (let i = 0; i < parts.length; i++) { - if (i % 2 === 0) { - parts[i] = parts[i] - .replace(/{/g, '\\{') - .replace(/}/g, '\\}') - // Escape < unless it can start a JSX tag (letter, /, $, _) or an - // HTML comment (