本文整理汇总了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>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`);
});
示例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);
}
示例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);
}
示例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>\`;
~~~~~`]);
});