Core: transformerIcon supports SVG string to extend codeblock icons

This commit is contained in:
Fuma Nama
2025-09-04 20:01:58 +08:00
parent 4082acc16f
commit d135efd200
2 changed files with 16 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-core': patch
---
`transformerIcon` supports SVG string to extend codeblock icons
@@ -1,10 +1,12 @@
import { type ShikiTransformer } from 'shiki';
export interface CodeBlockIcon {
viewBox: string;
fill: string;
d: string;
}
export type CodeBlockIcon =
| {
viewBox: string;
fill: string;
d: string;
}
| string;
const defaultShortcuts: Record<string, string> = {
js: 'javascript',
@@ -156,7 +158,10 @@ export function transformerIcon(options: IconOptions = {}): ShikiTransformer {
const icon = iconName in icons ? icons[iconName] : defaultIcon;
if (icon) {
pre.properties.icon = `<svg viewBox="${icon.viewBox}"><path d="${icon.d}" fill="${icon.fill}" /></svg>`;
pre.properties.icon =
typeof icon === 'string'
? icon
: `<svg viewBox="${icon.viewBox}"><path d="${icon.d}" fill="${icon.fill}" /></svg>`;
}
return pre;