Skip to content

Instantly share code, notes, and snippets.

@starakaj
Created July 8, 2021 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starakaj/3f48f129acb976ed097f18fb048fb284 to your computer and use it in GitHub Desktop.
Save starakaj/3f48f129acb976ed097f18fb048fb284 to your computer and use it in GitHub Desktop.
function translateSource(data: string, outPath: string) {
let paintStatements: t.Statement[] = [];
let viewBox: number[];
let inStyle = false;
const parser = new html2.Parser({
onopentag(name: string, attribs: {[s: string]: string}) {
// ...
else if (name === "svg") {
// Split the viewbox string on spaces and convert to numbers
viewBox = attribs["viewbox"].split(" ").map(Number.parseFloat);
}
else if (name === "style") {
inStyle = true;
}
},
ontext(data: string) {
if (inStyle) {
// parse CSS
}
},
onclosetag(name) {
if (name === "style") {
inStyle = false;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment