Created
July 8, 2021 20:55
-
-
Save starakaj/3f48f129acb976ed097f18fb048fb284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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