forked from jacobparis-insiders/sly
-
Couldn't load subscription status.
- Fork 0
Home
Justin Hall edited this page Dec 17, 2023
·
1 revision
sly.json:
{
"$schema": "https://sly-cli.fly.dev/registry/config.json",
"libraries": [
{
"name": "material-design-icons",
"directory": "./svg-icons",
"postinstall": [],
"transformers": ["./sly-transformers/svg-remove-dimensions.ts"]
},
{
"name": "@sly-cli/transformers",
"directory": "./sly-transformers",
"postinstall": [],
"transformers": []
}
]
}svg-remove-dimensions.ts:
import { parse } from "node-html-parser"
import type { Transformer } from "@sly-cli/sly"
/**
* Removes the width and height attributes from the SVG element
*/
const svgRemoveDimensions: Transformer = (input) => {
const root = parse(input)
const svg = root.querySelector("svg")
if (!svg) throw new Error("No SVG element found")
svg.removeAttribute("width")
svg.removeAttribute("height")
return root.toString()
}
export default svgRemoveDimensions;