mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
feat: add file name transformer for fenced code blocks (#535)
* feat: add file name transformer for fenced code blocks * chore: update file names in fenced code blocks
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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");
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user