当前位置: 首页>>代码示例>>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;未经允许,请勿转载。