當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。