mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-30 13:57:33 -07:00
27 lines
724 B
TypeScript
27 lines
724 B
TypeScript
import * as mfm from "mfm-js";
|
|
import { defaultStore } from "@/store";
|
|
import { expandKaTeXMacro } from "@/scripts/katex-macro";
|
|
|
|
export function preprocess(text: string): string {
|
|
if (defaultStore.state.enableCustomKaTeXMacro) {
|
|
const parsedKaTeXMacro =
|
|
localStorage.getItem("customKaTeXMacroParsed") ?? "{}";
|
|
const maxNumberOfExpansions = 200; // to prevent infinite expansion loops
|
|
|
|
let nodes = mfm.parse(text);
|
|
|
|
for (let node of nodes) {
|
|
if (node["type"] === "mathInline" || node["type"] === "mathBlock") {
|
|
node["props"]["formula"] = expandKaTeXMacro(
|
|
node["props"]["formula"],
|
|
parsedKaTeXMacro,
|
|
maxNumberOfExpansions,
|
|
);
|
|
}
|
|
}
|
|
|
|
text = mfm.toString(nodes);
|
|
}
|
|
|
|
return text;
|
|
}
|