當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。