本文整理匯總了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;
}