mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-18 07:18:38 +02:00
CODEBASE: Generate display data for math notation at built time and remove runtime mathjax dependency (#2447)
This commit is contained in:
46
tools/bundle-doc/generate-math-notation-output.mjs
Normal file
46
tools/bundle-doc/generate-math-notation-output.mjs
Normal file
@@ -0,0 +1,46 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import remarkMath from "remark-math";
|
||||
import remarkParse from "remark-parse";
|
||||
import remarkRehype from "remark-rehype";
|
||||
import { unified } from "unified";
|
||||
|
||||
import { createPlugin } from "../../src/ThirdParty/RehypePlugin.mjs";
|
||||
import { convertToMML, walkDir } from "./utils.mjs";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const data = {};
|
||||
const parser = unified().use(remarkParse).use(remarkMath);
|
||||
const tool = unified()
|
||||
.use(remarkRehype)
|
||||
.use(
|
||||
createPlugin(function () {
|
||||
return {
|
||||
render(value) {
|
||||
data[value] = convertToMML(value);
|
||||
return [];
|
||||
},
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
function processDir(dir) {
|
||||
walkDir(dir, (filePath) => {
|
||||
tool.runSync(parser.parse(readFileSync(filePath)));
|
||||
});
|
||||
}
|
||||
|
||||
processDir(resolve(__dirname, "../../src/Documentation/doc/en"));
|
||||
|
||||
const notationInput = JSON.parse(readFileSync(resolve(__dirname, "../../src/Documentation/data/MathNotation.json")));
|
||||
for (const value of Object.values(notationInput)) {
|
||||
data[value] = convertToMML(value);
|
||||
}
|
||||
console.log(`Generated MathML data for ${Object.keys(data).length} notation entries`);
|
||||
writeFileSync(resolve(__dirname, "../../src/Documentation/data/MathNotationOutput.json"), JSON.stringify(data), {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
Reference in New Issue
Block a user