Skip to content

Commit f0891e7

Browse files
committed
Fix LaTex
1 parent 11c8436 commit f0891e7

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

scripts/convert-adoc.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,19 @@ async function convertAdocFiles(directory, apiRoute = "contracts/5.x/api") {
119119
},
120120
);
121121

122-
// Fix curly bracket file references {filename} -> filename, but preserve braces in code blocks
123-
const parts = mdContent.split(/(```[\s\S]*?```)/g);
122+
// Fix curly bracket file references {filename} -> filename, but preserve
123+
// braces in code blocks and in math regions ($...$ / $$...$$) so LaTeX
124+
// like `\frac{u}{n}` survives.
125+
const parts = mdContent.split(
126+
/(```[\s\S]*?```|\$\$[\s\S]*?\$\$|\$[^$\n]+\$)/g,
127+
);
124128
mdContent = parts
125129
.map((part, index) => {
126-
// Every odd index is a code block (```...```)
130+
// Every odd index is a preserved region (code block or math).
127131
if (index % 2 === 1) {
128-
return part; // Preserve code blocks as-is
129-
} else {
130-
// Remove curly brackets from non-code-block parts only
131-
return part.replace(/\{([^}]+)\}/g, "$1");
132+
return part;
132133
}
134+
return part.replace(/\{([^}]+)\}/g, "$1");
133135
})
134136
.join("");
135137

@@ -260,17 +262,17 @@ function processFile(filePath) {
260262
}
261263

262264
const content = fsSync.readFileSync(filePath, "utf8");
263-
// Split content by code blocks and process non-code-block parts only
264-
const parts = content.split(/(```[\s\S]*?```)/g);
265+
// Split content by code blocks and math regions, process the rest.
266+
const parts = content.split(
267+
/(```[\s\S]*?```|\$\$[\s\S]*?\$\$|\$[^$\n]+\$)/g,
268+
);
265269
const modifiedContent = parts
266270
.map((part, index) => {
267-
// Every odd index is a code block (```...```)
271+
// Every odd index is a preserved region (code block or math).
268272
if (index % 2 === 1) {
269-
return part; // Preserve code blocks as-is
270-
} else {
271-
// Remove curly brackets from non-code-block parts
272-
return part.replace(/[{}]/g, "");
273+
return part;
273274
}
275+
return part.replace(/[{}]/g, "");
274276
})
275277
.join("");
276278

0 commit comments

Comments
 (0)