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