当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript predicates.parentMatches方法代码示例

本文整理汇总了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,
    });
  }
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:39,代码来源:html-parser.ts

示例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);
   }
 }
开发者ID:Polymer,项目名称:vulcanize,代码行数:22,代码来源:html-bundler.ts

示例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."
 */
开发者ID:MehdiRaash,项目名称:tools,代码行数:31,代码来源:matchers.ts


注:本文中的dom5.predicates.parentMatches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。