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


TypeScript html-parser.HtmlParser类代码示例

本文整理汇总了TypeScript中polymer-analyzer/lib/html/html-parser.HtmlParser的典型用法代码示例。如果您正苦于以下问题:TypeScript HtmlParser类的具体用法?TypeScript HtmlParser怎么用?TypeScript HtmlParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: suite

suite('getLocationInfoForPosition', () => {
  const parser = new HtmlParser();

  test('works for an empty string', () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('');
    assert.equal(allKindsSpaceSeparated, 'text');
  });

  test('works when just starting a tag', () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t');
    // We assume that you're starting to write an html tag in a text node, so
    // this works.
    assert.equal(allKindsSpaceSeparated, 'text text text');
  });

  test('works with a closed tag', () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t></t>');
    assert.equal(
        allKindsSpaceSeparated,
        'text tagName tagName text endTag endTag endTag text');
  });

  test('works with an unclosed tag', () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t>');
    assert.equal(allKindsSpaceSeparated, 'text tagName tagName text');
  });

  test('works for a closed tag with empty attributes section', () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t ></t>');
    assert.equal(
        allKindsSpaceSeparated,
        'text tagName tagName attribute text endTag endTag endTag text');
  });

  test('works for an unclosed tag with empty attributes section', () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t >');
    assert.equal(allKindsSpaceSeparated, 'text tagName tagName attribute text');
  });

  test('works for a closed tag with a boolean attribute', () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a></t>');
    assert.equal(
        allKindsSpaceSeparated, 'text tagName tagName attribute attribute ' +
            'text endTag endTag endTag text');
  });

  test('works for an unclosed tag with a boolean attribute', () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a>');
    assert.equal(
        allKindsSpaceSeparated,
        'text tagName tagName attribute attribute text');
  });

  test('works with an empty attribute value in a closed tag', () => {
    let allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=></t>');
    assert.equal(
        allKindsSpaceSeparated,
        'text tagName tagName attribute attribute attributeValue text ' +
            'endTag endTag endTag text');

    allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=""></t>');
    assert.equal(
        allKindsSpaceSeparated, 'text tagName tagName attribute attribute ' +
            'attributeValue attributeValue attributeValue text ' +
            'endTag endTag endTag text');

    allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=\'\'></t>');
    assert.equal(
        allKindsSpaceSeparated, 'text tagName tagName attribute attribute ' +
            'attributeValue attributeValue attributeValue text ' +
            'endTag endTag endTag text');
  });

  test('works with an empty attribute value in an unclosed tag', () => {
    let allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=>');
    assert.equal(
        allKindsSpaceSeparated,
        'text tagName tagName attribute attribute attributeValue text');

    allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a="">');
    assert.equal(
        allKindsSpaceSeparated,
        'text tagName tagName attribute attribute attributeValue attributeValue attributeValue text');

    allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t a=\'\'>');
    assert.equal(
        allKindsSpaceSeparated,
        'text tagName tagName attribute attribute attributeValue attributeValue attributeValue text');
  });

  test(`works with a closed tag with text content`, () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t> </t>');
    assert.equal(
        allKindsSpaceSeparated,
        'text tagName tagName text text endTag endTag endTag text');
  });

  test(`works with an unclosed tag with text content`, () => {
    const allKindsSpaceSeparated = getAllKindsSpaceSeparated('<t> ');
    assert.equal(allKindsSpaceSeparated, 'text tagName tagName text text');
//.........这里部分代码省略.........
开发者ID:MehdiRaash,项目名称:tools,代码行数:101,代码来源:ast-from-source-position_test.ts

示例2: getAllKindsSpaceSeparated

 /**
  * Return a space separated string of the `kind` for every location in the
  * given html text.
  *
  * For small documents you can just assert against this string. For larger
  * documents you can write a regexp to express your assertion.
  */
 function getAllKindsSpaceSeparated(text: string) {
   const doc =
       parser.parse(text, 'uninteresting file name.html' as ResolvedUrl);
   return getEveryPosition(text)
       .map(pos => getHtmlAstLocationForPosition(doc, pos).kind)
       .join(' ');
 }
开发者ID:asdfg9822,项目名称:polymer-editor-service,代码行数:14,代码来源:ast-from-source-position_test.ts


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