Skip to content

Instantly share code, notes, and snippets.

@starakaj

starakaj/code.js Secret

Created February 22, 2021 21:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save starakaj/e8d51ff1adfad8368945bd58acff3b93 to your computer and use it in GitHub Desktop.
import * as html2 from "htmlparser2";
// ...
const parser = new html2.Parser({
onopentag(name: string, attribs: {[s: string]: string}) {
if (name === "svg")
console.log("entering an svg tag");
},
onclosetag(name: string) {
if (name === "svg")
console.log("exiting an svg tag");
}
});
// ...
function translateSource(data: string, outPath: string) {
parser.parseComplete(data);
fs.writeFile(outPath, data, { encoding: "utf8" }, () => {
console.log(`Wrote output to ${outPath}`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment