Add support for Astro component

This commit is contained in:
pheralb
2025-04-15 14:21:29 +01:00
parent 0d8e929e4c
commit 021f810e2c
3 changed files with 88 additions and 3 deletions
+16
View File
@@ -0,0 +1,16 @@
interface AstroComponentParams {
svgContent: string;
}
export function getAstroCode({ svgContent }: AstroComponentParams): string {
const cleanedSvg = svgContent
.replace(/\s*(width|height)="[^"]*"/gi, '')
.replace(/\s*(width|height)='[^']*'/gi, '')
.replace(/\s*(width|height)=\{[^}]*\}/gi, '')
.replace(/<svg([^>]*)>/i, (match, attrs) => {
const cleanedAttrs = attrs.replace(/\s*\{?\.\.\.Astro\.props\}?\s*/i, '');
return `<svg ${cleanedAttrs} {...Astro.props}>`;
});
return cleanedSvg.trim();
}