我试图使用以下基于JS的插件格式化代码:https://github.com/beautify-web/js-beautify
所有的例子都在使用NodeJS (似乎)。我只是在寻找一个简单的香草/代码JavaScript解决方案。
就像这样:
let sourceContent = " function test() { ... }"
console.log(js-beautify(sourceContent));外面有可用的插件吗?jQuery解决方案也很好。
发布于 2019-07-05 21:25:49
示例使用nodejs,但是库也支持浏览器,正如自述的那样。
因此,添加(js美化)脚本标记,如自述:
<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);这里提到了web库:https://github.com/beautify-web/js-beautify/blob/master/README.md#web-library
这里提到了可用的web方法:https://github.com/beautify-web/js-beautify/blob/master/README.md#web-library-1
是的,您与js-beautify()的关系非常密切,而不是js_beautify() :)
https://stackoverflow.com/questions/56909326
复制相似问题