本文整理汇总了TypeScript中htmlparser2.Parser.end方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Parser.end方法的具体用法?TypeScript Parser.end怎么用?TypeScript Parser.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htmlparser2.Parser
的用法示例。
在下文中一共展示了Parser.end方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
onclosetag: function (name) {
// Terminate once last tag is closed
tags.pop();
if (!changeFound && tags.length === 0) {
parser.end();
}
},
示例2: function
onopentag: function (name: string, attribs: any) {
if (name === 'div' && !attribs.class) {
lineIndex++;
} else if (name === 'div' && attribs.class.indexOf('cldr folding') !== -1) {
foldFound = true;
parser.end();
}
},
示例3: toTree
function toTree(html: string) {
var tree = [];
var stack = [];
var parser = new htmlparser.Parser({
onopentag: function(name, attribs){
if (stack.length > 0) {
if (stack[stack.length - 1].child == undefined) {
stack[stack.length - 1].child = [];
}
var el = {name: name, attribs: attribs};
stack[stack.length - 1].child.push(el);
stack.push(el);
} else {
var el = {name: name, attribs: attribs};
tree.push(el);
stack.push(el);
}
},
ontext: function(text){
if(text.trim() != '') {
stack[stack.length - 1].text = text;
}
},
onclosetag: function(tagname){
stack.pop();
}
}, {decodeEntities: true});
parser.write(html);
parser.end();
return tree;
}