本文整理汇总了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
}
];
}
示例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;
}
示例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;
}
示例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)
}
示例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);
})();
示例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;
}
示例7: beautifyHtml
export const printPrettyHtml = (html)=> {
console.log("\n"+ beautifyHtml( html, {"indent_size":2} ).replace(/class=/g, "className=") )
}