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


TypeScript js-beautify.html函数代码示例

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


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

示例1: htmlFormat

export function htmlFormat(
  document: TextDocument,
  currRange: Range,
  formattingOptions: FormattingOptions,
  config: any
): TextEdit[] {
  const { value, range } = getValueAndRange(document, currRange);

  defaultHtmlOptions.indent_with_tabs = !formattingOptions.insertSpaces;
  defaultHtmlOptions.indent_size = formattingOptions.tabSize;

  const htmlFormattingOptions = _.assign(
    defaultHtmlOptions,
    config.tandem.paperclip.format.defaultFormatterOptions['js-beautify-html'],
    { end_with_newline: false }
  );

  const beautifiedHtml = htmlBeautify(templateHead + value + templateTail, htmlFormattingOptions);
  const wrappedHtml = beautifiedHtml.substring(templateHead.length, beautifiedHtml.length - templateTail.length);
  return [
    {
      range,
      newText: wrappedHtml
    }
  ];
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:26,代码来源:htmlFormat.ts

示例2: serializeDocument

export function serializeDocument(document: Object, pretty?: boolean): string {
  const doc = parse5.serialize(document, { treeAdapter : parse5.treeAdapters.htmlparser2 });
  if (pretty) {
    const beautify: any = require('js-beautify');
    return beautify.html(doc, {indent_size: 2});
  }
  return doc;
}
开发者ID:jeffwhelpley,项目名称:universal,代码行数:8,代码来源:node-document.ts

示例3: serializeDocument

export function serializeDocument(document: Object, pretty?: boolean): string {
  const doc = serializer.serialize(document);
  if (pretty) {
    const beautify: any = require('js-beautify');
    return beautify.html(doc, {indent_size: 2});
  }
  return doc;
}
开发者ID:carloserodriguez2000,项目名称:universal,代码行数:8,代码来源:node-document.ts

示例4: beautifyHtml

export const printPrettyHtml = (html)=> {
  html = beautifyHtml( html, {"indent_size":2} )
    .replace(/class=/g, "className=")
    .replace(/<input([^>]*)>/g, "<input$1/>")
    .replace(/readonly=""/g,"readOnly={true}")
    .replace(/font-size/g,"fontSize")
    .replace(/style="([^"]+)"+/g, (match, style)=> {
      let reactStyle = map(compact(style.split(";")), (keyvalue)=> {
        let [key, value] = keyvalue.split(":")
        return `${key}:"${value}"`
      }).join(",")
      return "style={{" + reactStyle + "}}"
    })
  console.log("\n"+ html)
}
开发者ID:BenJamesbabala,项目名称:searchkit,代码行数:15,代码来源:TestHelpers.ts

示例5: getAllFilePaths

(() => {
  const failures: Failure[] = [];
  const filePaths = nonFlagsArgs.length > 0 ? nonFlagsArgs : getAllFilePaths();

  for (const filePath of filePaths) {
    const fileContents = readFile(filePath);
    const formattedFileContents = fixSelfClosingSlashes(formatHtml(fileContents, beautifyOptions));

    if (fileContents !== formattedFileContents) {
      if (options.fix) {
        writeFile(filePath, formattedFileContents);
      } else {
        failures.push({ filePath, message: 'html formatting' });
      }
    }
  }

  bailIfFailures(failures);
})();
开发者ID:kevinphelps,项目名称:kevinphelps.me,代码行数:19,代码来源:format-html.ts

示例6: beautifyJsLibChainHtml

  // Post-parser cleanup routines.  The parser is for getting into structure of the doc.

  // cleanup the js <script> libs that are added after the main 'three.js' lib.
  // e.g make it so they're not all on one line.
  // We have to deal with this at the string level (text level) since I don't
  // know how to control formatting at the doc level.
  // Note: string is pass by value, so we get a copy of the text and we can manipulate
  // without altering the original.
  // <script src="../build/three.js"></script><!--vrize add start--><script src="js/vr/WebVR.js"></script><!--vrize add end--><!--vrize add start--><script src="js/vrize/vrize_kbd.js"></script><!--vrize add end-->
  beautifyJsLibChainHtml(text : string) {
    // let newText = text;

    // return newText;
    // text += "hello";
    // identify the "<script src=..three.js>" line.  This will be the long line
    // that has all the concatenated libs
    let regex = /<script\s+src=['"].*three\.js.*/
    let threeJsLibMatch = text.match(regex)

    // if found, pass to beautify
    if (threeJsLibMatch && threeJsLibMatch[0]) {
      let newText = beautify.html(threeJsLibMatch[0]);

      // and then sub it back in
      text = text.replace(regex, newText);
    }

    return text;

  }
开发者ID:vt5491,项目名称:threejs-vr-gallery,代码行数:30,代码来源:transformer.service.ts

示例7: beautifyHtml

export const printPrettyHtml = (html)=> {
  console.log("\n"+ beautifyHtml( html, {"indent_size":2} ).replace(/class=/g, "className=") )
}
开发者ID:Baltox,项目名称:searchkit,代码行数:3,代码来源:TestHelpers.ts


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