full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -3,7 +3,8 @@ import { toText } from "hast-util-to-text";
import { removePosition } from "unist-util-remove-position";
import { visitParents } from "unist-util-visit-parents";
const languagePattern = /\blanguage-(\S+)\b/;
async function highlightCodeBlocks(tree, highlighter) {
const defaultExcludeLanguages = ["math"];
async function highlightCodeBlocks(tree, highlighter, excludeLanguages = []) {
const nodes = [];
visitParents(tree, { type: "element", tagName: "code" }, (node, ancestors) => {
const parent = ancestors.at(-1);
@@ -28,12 +29,13 @@ async function highlightCodeBlocks(tree, highlighter) {
}
}
}
if (languageMatch?.[1] === "math") {
const language = languageMatch?.[1] || "plaintext";
if (excludeLanguages.includes(language) || defaultExcludeLanguages.includes(language)) {
return;
}
nodes.push({
node,
language: languageMatch?.[1] || "plaintext",
language,
parent,
grandParent: ancestors.at(-2)
});
@@ -41,13 +43,19 @@ async function highlightCodeBlocks(tree, highlighter) {
for (const { node, language, grandParent, parent } of nodes) {
const meta = node.data?.meta ?? node.properties.metastring ?? void 0;
const code = toText(node, { whitespace: "pre" });
const html = await highlighter(code, language, { meta });
const replacement = fromHtml(html, { fragment: true }).children[0];
removePosition(replacement);
const result = await highlighter(code, language, { meta });
let replacement;
if (typeof result === "string") {
replacement = fromHtml(result, { fragment: true }).children[0];
removePosition(replacement);
} else {
replacement = result.children[0];
}
const index = grandParent.children.indexOf(parent);
grandParent.children[index] = replacement;
}
}
export {
defaultExcludeLanguages,
highlightCodeBlocks
};