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:
Sat Naing
2025-06-14 00:14:07 +07:00
committed by GitHub
parent 38ebf6e1b6
commit cb8a4794be
9 changed files with 156 additions and 72 deletions
+39
View File
@@ -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");
},
});