in jshint-server/src/server.ts [524:558]
private getEmbeddedJavascript(html: string): string {
let embeddedJS = [];
let index = 0;
let inscript = false;
let parser = new htmlparser.Parser({
onopentag: (name, attribs) => {
if (name === "script" && attribs.type === "text/javascript") {
// Push new lines for lines between previous script tag and this one to preserve location information
embeddedJS.push.apply(embeddedJS, html.slice(index, parser.endIndex).match(/\n\r|\n|\r/g));
inscript = true;
}
},
ontext(data) {
if (!inscript) {
return;
}
// Collect JavaScript code
embeddedJS.push(data);
},
onclosetag: (name) => {
if (name !== "script" || !inscript) {
return;
}
index = parser.startIndex;
inscript = false;
}
});
parser.write(html);
parser.end();
return embeddedJS.join("");
}