Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions generate-adaptors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,30 @@ function pushToPaths(name) {
});
}

function generateJsDoc(a) {
// Add line break before </dt> tags and escape curly braces outside of code blocks
let docsContent = JSON.parse(a.docs).replace(/<\/dt>/g, '\n</dt>');

// 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 (<!--)
.replace(/<(?![A-Za-z/$_!])/g, '\\<');
}
}

docsContent = parts.join('');

return parts.join('');
}

function generateJsDoc(a) {
// Add line break before </dt> tags and escape MDX specials outside code blocks
const docsContent = escapeMdx(JSON.parse(a.docs).replace(/<\/dt>/g, '\n</dt>'));

return `---
title: ${a.name}@${a.version}
Expand All @@ -128,7 +136,7 @@ keywords:

# Changelog for the ${a.name} adaptor

${JSON.parse(a.changelog)}`;
${escapeMdx(JSON.parse(a.changelog))}`;
}

function generateReadme(a) {
Expand All @@ -145,7 +153,7 @@ keywords:

Source: https://github.com/OpenFn/adaptors/tree/main/packages/${a.name}

${JSON.parse(a.readme)}`;
${escapeMdx(JSON.parse(a.readme))}`;
}

const sampleConfiguration = json => {
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"@docusaurus/preset-classic": "3.10.1",
"@docusaurus/theme-mermaid": "3.10.1",
"@mdx-js/react": "^3.0.0",
"axios": "1.16.0",
"brace-expansion": "^5.0.0",
"axios": "1.18.0",
"brace-expansion": "^5.0.8",
"clsx": "^1.1.1",
"compare-versions": "^5.0.1",
"date-fns": "2.21.3",
"form-data": "4.0.4",
"form-data": "4.0.6",
"mermaid": "11.15.0",
"prism-react-renderer": "^2.1.0",
"raw-loader": "^4.0.2",
Expand All @@ -40,7 +40,7 @@
"react-flow-renderer": "^9.6.8",
"react-particles": "^2.5.3",
"react-player": "^2.9.0",
"sharp": "^0.34.2",
"sharp": "^0.35.0",
"tsparticles": "^2.5.3"
},
"browserslist": {
Expand Down Expand Up @@ -71,6 +71,7 @@
"trim": "^0.0.3",
"got": "^11.8.5",
"cytoscape": "3.28.1",
"mermaid@>=11.6.0": "11.15.0",
"glob": "^11.1.0"
},
"engines": {
Expand Down
Loading