当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Parser.write方法代码示例

本文整理汇总了TypeScript中htmlparser2.Parser.write方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Parser.write方法的具体用法?TypeScript Parser.write怎么用?TypeScript Parser.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在htmlparser2.Parser的用法示例。


在下文中一共展示了Parser.write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

			return new Promise<number>((res, rej) => {
				let lineIndex: number = 0;
				let changeFound: boolean;
				let tags: string[] = [];
				let parser = new htmlparser.Parser({
					onopentag: function (name: string, attribs: any) {
						tags.push(name);
						if (name === 'div' && !attribs.class) {
							lineIndex++;
						} else if (name === 'div' && attribs.class === changeClass) {
							changeFound = true;
							parser.end();
						}
					},
					onclosetag: function (name) {
						// Terminate once last tag is closed
						tags.pop();
						if (!changeFound && tags.length === 0) {
							parser.end();
						}
					},
					onend: function () {
						if (!changeFound) {
							return rej(`No changes in the diff found.`);
						}
						return res(lineIndex);
					}
				});
				parser.write(html);
			});
开发者ID:kieferrm,项目名称:vscode,代码行数:30,代码来源:git.ts

示例2: Promise

		return new Promise(async (res, rej) => {
			const html = await this.spectron.waitFor(this.spectron.client.getHTML, selector);
			let lineIndex: number = 0;
			let stringFound: boolean;
			let parser = new htmlparser.Parser({
				onopentag: function (name: string, attribs: any) {
					if (name === 'div' && attribs.class === 'view-line') {
						lineIndex++;
					}
				},
				ontext: function (text) {
					if (!stringFound && text === string) {
						stringFound = true;
						parser.end();
					}
				},
				onend: function () {
					if (!stringFound) {
						return rej(`No ${string} in editor found.`);
					}
					return res(lineIndex);
				}
			});
			parser.write(html);
		});
开发者ID:naturtle,项目名称:vscode,代码行数:25,代码来源:javascript.ts

示例3: make

/**
 * 将 source 转换成 dom 节点树
 *
 * @param {string} source
 * @returns
 */
function make (source: string) {
  let handler = new htmlparser.DomHandler()
  let parser = new htmlparser.Parser(handler, {
    lowerCaseAttributeNames: false
  })

  parser.write(source)
  parser.done()
  return handler.dom
}
开发者ID:bbxyard,项目名称:bbxyard,代码行数:16,代码来源:dom.ts

示例4: function

			return new Promise<number>((res, rej) => {
				let lineIndex: number = 0;
				let foldFound: boolean;
				let parser = new htmlparser.Parser({
					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();
						}
					},
					onend: function () {
						if (!foldFound) {
							return rej(`No foldable elements found.`);
						}
						return res(lineIndex);
					}
				});
				parser.write(html);
			});
开发者ID:armanio123,项目名称:vscode,代码行数:21,代码来源:javascript.ts

示例5: 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;
}
开发者ID:Diullei,项目名称:atom-tsd,代码行数:36,代码来源:util.ts


注:本文中的htmlparser2.Parser.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。