【问题标题】:How to format/beautify HTML, CSS and JavaScript code in core JavaScript? [closed]如何在核心 JavaScript 中格式化/美化 HTML、CSS 和 JavaScript 代码? [关闭]
【发布时间】:2019-07-05 21:17:40
【问题描述】:

我正在尝试使用以下基于 JS 的插件来格式化代码: https://github.com/beautify-web/js-beautify

所有示例都使用 NodeJS(似乎)。我只是在寻找一个简单的 vanilla/code JavaScript 解决方案。

类似这样的:

let sourceContent = " function test() { ... }"
console.log(js-beautify(sourceContent));

那里有可用的插件吗? jQuery 解决方案也可以。

【问题讨论】:

标签: javascript jquery js-beautify


【解决方案1】:

示例使用 nodejs,但该库也支持浏览器,如自述文件中所述。

所以添加自述文件中提到的(js beautify)脚本标签:

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.10.0/beautify-js.min.js"></script>

那么你可以使用下面的示例代码:

const sourceContent = "function test() { ... }";
const beautified = js_beautify(sourceContent);

这里提到了网络库: https://github.com/beautify-web/js-beautify/blob/master/README.md#web-library

这里提到了可用的网络方法:https://github.com/beautify-web/js-beautify/blob/master/README.md#web-library-1

所以,是的,您与 js-beautify() 而不是 js_beautify() 非常接近 :)

【讨论】:

    猜你喜欢
    • 2010-12-30
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    • 2023-03-22
    • 2011-03-14
    • 1970-01-01
    相关资源
    最近更新 更多