diff --git a/generate-adaptors/index.js b/generate-adaptors/index.js index 88b4d2b66c85..cc787abffd9f 100644 --- a/generate-adaptors/index.js +++ b/generate-adaptors/index.js @@ -87,22 +87,30 @@ function pushToPaths(name) { }); } -function generateJsDoc(a) { - // Add line break before tags and escape curly braces outside of code blocks - let docsContent = JSON.parse(a.docs).replace(/<\/dt>/g, '\n'); - +// 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 = docsContent.split(codeBlockRegex); - - // Escape curly braces only in non-code parts (odd indices are code blocks) + 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) { // Non-code parts - parts[i] = parts[i].replace(/{/g, '\\{').replace(/}/g, '\\}'); + 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 (