本文整理匯總了TypeScript中dom5.predicates.parentMatches方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript predicates.parentMatches方法的具體用法?TypeScript predicates.parentMatches怎麽用?TypeScript predicates.parentMatches使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dom5.predicates
的用法示例。
在下文中一共展示了predicates.parentMatches方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: parse
/**
* Parse html into ASTs.
*
* @param {string} htmlString an HTML document.
* @param {string} href is the path of the document.
*/
parse(
contents: string, url: ResolvedUrl, urlResolver: UrlResolver,
inlineInfo?: InlineDocInfo<any>): ParsedHtmlDocument {
const ast = parseHtml(contents, {locationInfo: true});
// There should be at most one <base> tag and it must be inside <head> tag.
const baseTag = query(
ast,
p.AND(
p.parentMatches(p.hasTagName('head')),
p.hasTagName('base'),
p.hasAttr('href')));
let baseUrl;
if (baseTag) {
const baseHref = getAttribute(baseTag, 'href')! as FileRelativeUrl;
baseUrl = urlResolver.resolve(baseHref, url, undefined);
} else {
baseUrl = url;
}
const isInline = !!inlineInfo;
inlineInfo = inlineInfo || {};
return new ParsedHtmlDocument({
url,
baseUrl,
contents,
ast,
locationOffset: inlineInfo.locationOffset,
astNode: inlineInfo.astNode,
isInline,
});
}
示例2: _attachHiddenDiv
/**
* Set the hidden div at the appropriate location within the document. The
* goal is to place the hidden div at the same place as the first html
* import. However, the div can't be placed in the `<head>` of the document
* so if first import is found in the head, we prepend the div to the body.
* If there is no body, we'll just attach the hidden div to the document at
* the end.
*/
private _attachHiddenDiv(ast: ASTNode, hiddenDiv: ASTNode) {
const firstHtmlImport = dom5.query(ast, matchers.eagerHtmlImport);
const body = dom5.query(ast, matchers.body);
if (body) {
if (firstHtmlImport &&
dom5.predicates.parentMatches(matchers.body)(firstHtmlImport)) {
insertAfter(firstHtmlImport, hiddenDiv);
} else {
prepend(body, hiddenDiv);
}
} else {
dom5.append(ast, hiddenDiv);
}
}
示例3:
predicates.OR(
predicates.hasAttrValue('type', 'text/html'),
predicates.hasAttrValue('type', 'html'),
predicates.NOT(predicates.hasAttr('type'))));
export const htmlImport: Matcher =
predicates.OR(eagerHtmlImport, lazyHtmlImport);
export const stylesheetImport: Matcher = predicates.AND(
predicates.hasTagName('link'),
predicates.hasAttrValue('rel', 'import'),
predicates.hasAttr('href'),
predicates.hasAttrValue('type', 'css'));
export const hiddenDiv: Matcher = predicates.AND(
predicates.hasTagName('div'),
predicates.hasAttr('hidden'),
predicates.hasAttr('by-polymer-bundler'));
export const inHiddenDiv: Matcher = predicates.parentMatches(hiddenDiv);
export const elementsWithUrlAttrsToRewrite: Matcher = predicates.AND(
predicates.OR(
...constants.URL_ATTR.map((attr) => predicates.hasAttr(attr))),
predicates.NOT(predicates.AND(
predicates.parentMatches(predicates.hasTagName('dom-module')),
lazyHtmlImport)));
/**
* TODO(usergenic): From garlicnation's PR comment - "This matcher needs to deal
* with a number of edge cases. Whitespace-only text nodes should be ignored,
* text nodes with meaningful space should be preserved. Comments should be
* ignored if --strip-comments is set. License comments should be deduplicated
* and moved to the start of the document."
*/