mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
cb8a4794be
* feat: add file name transformer for fenced code blocks * chore: update file names in fenced code blocks
40 lines
836 B
JavaScript
40 lines
836 B
JavaScript
export const transformerFileName = () => ({
|
|
pre(node) {
|
|
const raw = this.options.meta?.__raw?.split(" ");
|
|
|
|
if (!raw) return;
|
|
|
|
const metaMap = new Map();
|
|
|
|
for (const item of raw) {
|
|
const [key, value] = item.split("=");
|
|
metaMap.set(key, value.replace(/["'`]/g, ""));
|
|
}
|
|
|
|
const file = metaMap.get("file");
|
|
|
|
if (!file) return;
|
|
|
|
node.children.push({
|
|
type: "element",
|
|
tagName: "span",
|
|
properties: {
|
|
class: [
|
|
"px-2 py-1",
|
|
"absolute left-0 -top-6",
|
|
"rounded-t-md border border-b-0",
|
|
"bg-muted/50 text-foreground text-xs font-medium leading-4",
|
|
],
|
|
},
|
|
children: [
|
|
{
|
|
type: "text",
|
|
value: file,
|
|
},
|
|
],
|
|
});
|
|
|
|
this.addClassToHast(node, "mt-12 rounded-tl-none");
|
|
},
|
|
});
|