mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Added new types for domelementtype * Modify existing types for htmlparser2 * Updating PULL_REQUEST_TEMPLATE.md * Revert changes to .github/PULL_REQUEST_TEMPLATE.md * Fixed missing optional * Adding DomUtils * Update dependencies * Removed requirement for TypeScript 2.1 and updated test * Updated test to include DomUtils and DomHandlerOptions. * Updated domhandler tests * Remove incorrect constructor in Parser * Remove incorrect constructor in WritableStream * Change way of importing in tests * Adding deprecated fallback to Options * Add deprecated Options as a fallback to sanitize-html * Add ParserOptions * Use the deprecated Options
31 lines
870 B
TypeScript
31 lines
870 B
TypeScript
/**
|
|
* Created by staticfunction on 8/4/14.
|
|
*/
|
|
import htmlparser = require('htmlparser2');
|
|
|
|
const options: htmlparser.DomHandlerOptions = { withEndIndices: false, withDomLvl1: true }
|
|
const dh = new htmlparser.DomHandler((err: Error, dom: htmlparser.DomElement[]) => {
|
|
if(err) {
|
|
throw err;
|
|
}
|
|
|
|
// Use DomUtils to get name of first element in dom
|
|
console.log(htmlparser.DomUtils.getName(dom[0]));
|
|
}, options);
|
|
dh.onopentag = (name:string, attribs:{[s:string]:string}) => {
|
|
if(name === "script" && attribs['type'] === "text/javascript"){
|
|
console.log("JS! Hooray!");
|
|
}
|
|
};
|
|
dh.ontext = (text: string) => {
|
|
console.log("-->", text);
|
|
};
|
|
dh.onclosetag = () => {
|
|
console.log("That's it?!");
|
|
};
|
|
|
|
var parser = new htmlparser.Parser(dh);
|
|
|
|
parser.write("Xyz <script type='text/javascript'>var foo = '<<bar>>';</script>");
|
|
parser.end();
|