我有一个小型 Web 应用程序,它在最后输出 html 和 css 代码,但有必要重新缩进输出,尤其是 css。我找到了这个库:https://github.com/beautify-web/js-beautify 但这似乎不起作用。例如,其中一个文件显示:
Usage:
style_html(html_source);
style_html(html_source, options);
但我得到的只是一个错误:style_html 未定义。我已经包含了一组脚本标签,如使用部分所述。
示例:
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.6.8/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.6.8/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.6.8/beautify-html.min.js"></script>
<script> style_html("asdf");</script>
有什么想法吗?
最佳答案
参见the source code :
// If we're running a web page and don't have either of the above, add our one global window.html_beautify = function(html_source, options) { return style_html(html_source, options, window.js_beautify, window.css_beautify); };
全局称为html_beautify
,而不是style_html
(这是一个仅在内部使用的函数)。
关于javascript - 使用 Javascript 缩进 HTML 和 CSS 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42156756/