當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript index-next.queryAll函數代碼示例

本文整理匯總了TypeScript中dom5/lib/index-next.queryAll函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript queryAll函數的具體用法?TypeScript queryAll怎麽用?TypeScript queryAll使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了queryAll函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

    test('works for elements', async () => {
      const liTags =
          [...dom5.queryAll(document.ast, dom5.predicates.hasTagName('li'))];

      assert.equal(liTags.length, 4);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(liTags[0]!)!),
          `
        <li>1
        ~~~~~
        <li>2</li>
~~~~~~~~`);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(liTags[1]!)!),
          `
        <li>2</li>
        ~~~~~~~~~~`);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(liTags[2]!)), `
        <li><li>
        ~~~~`);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(liTags[3]!)), `
        <li><li>
            ~~~~
      </ul>
~~~~~~`);

      const pTags =
          [...dom5.queryAll(document.ast, dom5.predicates.hasTagName('p'))];
      assert.equal(pTags.length, 2);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(pTags[0]!)), `
    <p>
    ~~~
      This is a paragraph without a closing tag.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    <p>This is a paragraph with a closing tag.</p>
~~~~`);

      assert.deepEqual(
          await underliner.underline(document.sourceRangeForNode(pTags[1]!)), `
    <p>This is a paragraph with a closing tag.</p>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`);
    });
開發者ID:MehdiRaash,項目名稱:tools,代碼行數:50,代碼來源:html-document_test.ts

示例2: html

export function html(text: string) {
  const ast = parse5.parse(text);
  const styleNodes = dom5.queryAll(
      ast, isInlineStyle, dom5.childNodesIncludeTemplate);
  for (const styleNode of styleNodes) {
    const text = dom5.getTextContent(styleNode);
    dom5.setTextContent(styleNode, css(text));
  }
  return parse5.serialize(ast);
}
開發者ID:poehlmann,項目名稱:EvaluacionDiferencialDeLaMemoria,代碼行數:10,代碼來源:index.ts

示例3: replaceGiantScripts

/**
 * Replaces the Babel helpers, Require.js AMD loader, and WCT hack inline
 * scripts into just some comments, to make test comparison simpler.
 */
function replaceGiantScripts(html: string): string {
  const document = parse5.parse(html);
  for (const script of dom5.queryAll(
           document, dom5.predicates.hasTagName('script'))) {
    const js = dom5.getTextContent(script);
    if (js.includes('var requirejs,require')) {
      dom5.setTextContent(script, '// amd loader');
    } else if (js.includes('babelHelpers={}')) {
      dom5.setTextContent(script, '// babel helpers');
    } else if (js.includes('window._wctCallback =')) {
      dom5.setTextContent(script, '// wct hack 1/2');
    } else if (js.includes('window._wctCallback()')) {
      dom5.setTextContent(script, '// wct hack 2/2');
    }
  }
  return parse5.serialize(document);
}
開發者ID:Polymer,項目名稱:polymer-build,代碼行數:21,代碼來源:html-transform_test.ts

示例4: async

 test.skip(testName, async () => {
   const {document, underliner, url} = await analyzeContents('index.js', `
     html\`\\n\\n<div>Hello world</div>\`;
   `);
   const documents = document.getFeatures({kind: 'document'});
   assert.deepEqual(
       [...documents].map((d) => [d.url, d.type, d.isInline]),
       [[url, 'js', false], [url, 'html', true]]);
   const [htmlDocument] = document.getFeatures({kind: 'html-document'});
   assert.deepEqual(
       htmlDocument.parsedDocument.contents, '\n\n<div>Hello world</div>');
   const elements = [...dom5.queryAll(
       htmlDocument.parsedDocument.ast, dom5.predicates.hasTagName('div'))];
   const ranges = elements.map(
       (el) => htmlDocument.parsedDocument.sourceRangeForStartTag(el));
   assert.deepEqual(await underliner.underline(ranges), [`
     html\`\\n\\n<div>Hello world</div>\`;
               ~~~~~`]);
 });
開發者ID:MehdiRaash,項目名稱:tools,代碼行數:19,代碼來源:html-template-literal-scanner_test.ts


注:本文中的dom5/lib/index-next.queryAll函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。