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


TypeScript index-next.getTextContent函数代码示例

本文整理汇总了TypeScript中dom5/lib/index-next.getTextContent函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getTextContent函数的具体用法?TypeScript getTextContent怎么用?TypeScript getTextContent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getTextContent函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: ScannedScriptTagImport

    const myVisitor: HtmlVisitor = (node) => {
      if (isJsScriptNode(node)) {
        const src =
            dom5.getAttribute(node, 'src') as FileRelativeUrl | undefined;
        if (src) {
          features.push(new ScannedScriptTagImport(
              src,
              document.sourceRangeForNode(node)!,
              document.sourceRangeForAttributeValue(node, 'src')!,
              {language: 'html', node, containingDocument: document},
              dom5.getAttribute(node, 'type') === 'module'));
        } else {
          const locationOffset =
              getLocationOffsetOfStartOfTextContent(node, document);
          const attachedCommentText = getAttachedCommentText(node) || '';
          const contents = dom5.getTextContent(node);

          features.push(new ScannedInlineDocument(
              'js',
              contents,
              locationOffset,
              attachedCommentText,
              document.sourceRangeForNode(node)!,
              {language: 'html', node, containingDocument: document}));
        }
      }
    };
开发者ID:MehdiRaash,项目名称:tools,代码行数:27,代码来源:html-script-scanner.ts

示例2: transformEsModuleToAmd

function transformEsModuleToAmd(
    script: dom5.Node, idx: number, jsOptions: JsTransformOptions|undefined) {
  // We're not a module anymore.
  dom5.removeAttribute(script, 'type');

  if (scriptWasSplitByHtmlSplitter(script)) {
    // Nothing else to do here. If we're using HtmlSplitter, the JsTransformer
    // is responsible for doing this transformation.
    return;
  }

  const isExternal = dom5.hasAttribute(script, 'src');
  if (isExternal) {
    const src = dom5.getAttribute(script, 'src');
    dom5.removeAttribute(script, 'src');
    dom5.setTextContent(script, `define(['${src}']);`);

  } else {
    // Transform inline scripts with the AMD Babel plugin transformer.
    const newJs = jsTransform(dom5.getTextContent(script), {
      ...jsOptions,
      transformModulesToAmd: true,
      moduleScriptIdx: idx,
    });
    dom5.setTextContent(script, newJs);
  }
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:27,代码来源:html-transform.ts

示例3: 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

示例4: addIndentation

export function addIndentation(
    textNode: dom5.Node, additionalIndentation = '  ') {
  if (!dom5.isTextNode(textNode)) {
    return;
  }
  const text = dom5.getTextContent(textNode);
  const indentedText =
      text.split('\n')
          .map((line) => {
            return line.length > 0 ? additionalIndentation + line : line;
          })
          .join('\n');
  dom5.setTextContent(textNode, indentedText);
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:14,代码来源:util.ts

示例5: 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

示例6: removeTrailingWhitespace

export function removeTrailingWhitespace(
    textNode: dom5.Node, parsedDocument: ParsedHtmlDocument) {
  const prevText = dom5.getTextContent(textNode);
  const match = prevText.match(/\n?[ \t]*$/);
  if (!match) {
    return;
  }
  const range = parsedDocument.sourceRangeForNode(textNode)!;
  const lengthOfPreviousLine =
      parsedDocument.newlineIndexes[range.end.line - 1] -
      (parsedDocument.newlineIndexes[range.end.line - 2] || -1) - 1;
  const newRange: SourceRange = {
    ...range,
    start: {
      column: lengthOfPreviousLine,
      line: range.end.line - 1,
    }
  };
  return {range: newRange, replacementText: ''};
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:20,代码来源:util.ts

示例7: 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('window.define=')) {
      dom5.setTextContent(script, '// amd loader');
    } else if (js.includes('wrapNativeSuper=')) {
      dom5.setTextContent(script, '// babel helpers full');
    } else if (js.includes('interopRequireDefault=')) {
      dom5.setTextContent(script, '// babel helpers amd');
    } else if (js.includes('regeneratorRuntime')) {
      dom5.setTextContent(script, '// regenerator runtime');
    } 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:MehdiRaash,项目名称:tools,代码行数:25,代码来源:html-transform_test.ts

示例8: transformEsModuleToAmd

function transformEsModuleToAmd(
    script: dom5.Node, idx: number, jsOptions: JsTransformOptions|undefined) {
  // We're not a module anymore.
  dom5.removeAttribute(script, 'type');

  if (scriptWasSplitByHtmlSplitter(script)) {
    // Nothing else to do here. If we're using HtmlSplitter, the JsTransformer
    // is responsible for doing this transformation.
    return;
  }

  // Module scripts execute in order. AMD modules don't necessarily preserve
  // this ordering. To emulate the ordering, we construct an artificial
  // dependency chain between all module scripts on the page.
  const generatedModule = generateModuleName(idx);
  const previousGeneratedModule =
      idx === 0 ? undefined : generateModuleName(idx - 1);

  const isExternal = dom5.hasAttribute(script, 'src');
  if (isExternal) {
    const deps = [];
    if (previousGeneratedModule !== undefined) {
      deps.push(previousGeneratedModule);
    }
    const externalSrc = dom5.getAttribute(script, 'src');
    deps.push(externalSrc);
    const depsStr = deps.map((dep) => `'${dep}'`).join(', ');
    dom5.removeAttribute(script, 'src');
    dom5.setTextContent(script, `define('${generatedModule}', [${depsStr}]);`);

  } else {
    // Transform inline scripts with the AMD Babel plugin transformer.
    const newJs = jsTransform(dom5.getTextContent(script), {
      ...jsOptions,
      transformModulesToAmd: true,
      moduleScriptIdx: idx,
    });
    dom5.setTextContent(script, newJs);
  }
}
开发者ID:Polymer,项目名称:polymer-build,代码行数:40,代码来源:html-transform.ts

示例9: getIndentationInside

export function getIndentationInside(parentNode: dom5.Node) {
  if (!parentNode.childNodes || parentNode.childNodes.length === 0) {
    return '';
  }
  const firstChild = parentNode.childNodes[0];
  if (!dom5.isTextNode(firstChild)) {
    return '';
  }
  const text = dom5.getTextContent(firstChild);
  const match = text.match(/(^|\n)([ \t]+)/);
  if (!match) {
    return '';
  }
  // If the it's an empty node with just one line of whitespace, like this:
  //     <div>
  //     </div>
  // Then the indentation of actual content inside is one level deeper than
  // the whitespace on that second line.
  if (parentNode.childNodes.length === 1 && text.match(/^\n[ \t]+$/)) {
    return match[2] + '  ';
  }
  return match[2];
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:23,代码来源:util.ts

示例10: async

 const visitor = async (node: ASTNode) => {
   if (isStyleNode(node)) {
     const tagName = node.nodeName;
     if (tagName === 'link') {
       const href = dom5.getAttribute(node, 'href')! as FileRelativeUrl;
       features.push(new ScannedImport(
           'html-style',
           href,
           document.sourceRangeForNode(node)!,
           document.sourceRangeForAttributeValue(node, 'href')!,
           {language: 'html', node, containingDocument: document},
           true));
     } else {
       const contents = dom5.getTextContent(node);
       const locationOffset =
           getLocationOffsetOfStartOfTextContent(node, document);
       const commentText = getAttachedCommentText(node) || '';
       features.push(new ScannedInlineDocument(
           'css',
           contents,
           locationOffset,
           commentText,
           document.sourceRangeForNode(node)!,
           {language: 'html', node, containingDocument: document}));
     }
   }
   // Descend into templates.
   if (node.tagName === 'template') {
     const content = treeAdapters.default.getTemplateContent(node);
     if (content) {
       for (const n of dom5.depthFirst(content)) {
         visitor(n);
       }
     }
   }
 };
开发者ID:MehdiRaash,项目名称:tools,代码行数:36,代码来源:html-style-scanner.ts


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