+6
-1
astro.config.mjs
+6
-1
astro.config.mjs
···
8
8
9
9
import tailwind from "@astrojs/tailwind";
10
10
11
+
import { filenameTransformer } from "./src/scripts/filename-transformer";
12
+
11
13
const tailwindIntegration = tailwind({
12
14
applyBaseStyles: false,
13
15
});
···
17
19
integrations: [mdx(), tailwindIntegration],
18
20
legacy: { collections: true },
19
21
markdown: {
20
-
shikiConfig: { theme: "catppuccin-mocha" },
22
+
shikiConfig: {
23
+
theme: "catppuccin-mocha",
24
+
transformers: [filenameTransformer()],
25
+
},
21
26
},
22
27
});
+25
src/scripts/filename-transformer.ts
+25
src/scripts/filename-transformer.ts
···
1
+
// SPDX-FileCopyrightText: 2025 Norbert Melzer
2
+
// SPDX-FileContributor: Norbert Melzer
3
+
//
4
+
// SPDX-License-Identifier: MIT
5
+
6
+
import type { ShikiTransformer } from "shiki";
7
+
8
+
export function filenameTransformer(): ShikiTransformer {
9
+
const transformer: ShikiTransformer = {
10
+
name: "filenameTransformer",
11
+
12
+
pre(code) {
13
+
const meta: string = this.options.meta?.__raw || "";
14
+
const pattern = /(?:data-)?filename="(.*)"/;
15
+
16
+
const filename = pattern.exec(meta)?.[1] || null;
17
+
18
+
if (filename) {
19
+
code.properties.dataFilename = filename;
20
+
}
21
+
},
22
+
};
23
+
24
+
return transformer;
25
+
}