mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-24 03:21:20 -05:00
fix: shiki package update from version 0.14.7 to 1.22.0 (#3542)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com> Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com>
This commit is contained in:
+27
-15
@@ -2,9 +2,19 @@ import { slugifyWithCounter } from "@sindresorhus/slugify";
|
||||
import * as acorn from "acorn";
|
||||
import { toString } from "mdast-util-to-string";
|
||||
import { mdxAnnotations } from "mdx-annotations";
|
||||
import { getHighlighter, renderToHtml } from "shiki";
|
||||
import { createCssVariablesTheme, createHighlighter } from "shiki";
|
||||
import { visit } from "unist-util-visit";
|
||||
|
||||
let highlighterPromise;
|
||||
const supportedLanguages = ["javascript", "html", "shell", "tsx", "json", "yml", "ts"];
|
||||
|
||||
const myTheme = createCssVariablesTheme({
|
||||
name: "css-variables",
|
||||
variablePrefix: "--shiki-",
|
||||
variableDefaults: {},
|
||||
fontStyle: true,
|
||||
});
|
||||
|
||||
const rehypeParseCodeBlocks = () => {
|
||||
return (tree) => {
|
||||
visit(tree, "element", (node, _nodeIndex, parentNode) => {
|
||||
@@ -15,29 +25,31 @@ const rehypeParseCodeBlocks = () => {
|
||||
};
|
||||
};
|
||||
|
||||
let highlighter;
|
||||
|
||||
const getHighlighter = async () => {
|
||||
if (!highlighterPromise) {
|
||||
highlighterPromise = createHighlighter({
|
||||
langs: supportedLanguages,
|
||||
themes: [myTheme],
|
||||
})
|
||||
}
|
||||
|
||||
return highlighterPromise;
|
||||
}
|
||||
const rehypeShiki = () => {
|
||||
return async (tree) => {
|
||||
highlighter = highlighter ?? (await getHighlighter({ theme: "css-variables" }));
|
||||
const highlighter = await getHighlighter();
|
||||
|
||||
visit(tree, "element", (node) => {
|
||||
if (node.tagName === "pre" && node.children[0]?.tagName === "code") {
|
||||
let codeNode = node.children[0];
|
||||
let textNode = codeNode.children[0];
|
||||
|
||||
if (!codeNode || !textNode) return;
|
||||
node.properties.code = textNode.value;
|
||||
|
||||
if (node.properties.language) {
|
||||
let tokens = highlighter.codeToThemedTokens(textNode.value, node.properties.language);
|
||||
|
||||
textNode.value = renderToHtml(tokens, {
|
||||
elements: {
|
||||
pre: ({ children }) => children,
|
||||
code: ({ children }) => children,
|
||||
line: ({ children }) => `<span>${children}</span>`,
|
||||
},
|
||||
});
|
||||
if (codeNode.properties.className && codeNode.properties.className.length > 0) {
|
||||
let lang = codeNode.properties.className[0].replace("language-", "");
|
||||
const code = highlighter.codeToHtml(textNode.value, { lang, theme: "css-variables" });
|
||||
textNode.value = code;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
"remark-mdx": "3.0.1",
|
||||
"schema-dts": "1.1.2",
|
||||
"sharp": "0.33.5",
|
||||
"shiki": "0.14.7",
|
||||
"shiki": "1.22.0",
|
||||
"simple-functional-loader": "1.2.1",
|
||||
"tailwindcss": "3.4.13",
|
||||
"unist-util-filter": "5.0.1",
|
||||
|
||||
Reference in New Issue
Block a user