javascript - 使用 Javascript 缩进 HTML 和 CSS 代码

标签 javascript html css indentation

我有一个小型 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/

相关文章:

php - 将框推到页面顶部而不与其他内容重叠

javascript - 在文档中的所有元素完全加载后,触发 JS 事件的最可靠方法是什么?

javascript - 点击parent "li"元素需要打开underlaying "ul"

java - Html 元素未在 Outlook 正文中转换

java - Thymeleaf - 使用动态 url 生成图像 url

javascript - 在 JavaScript 中清除特定时间限制后的间隔

javascript - window.location.assign ("link"), 不工作

css - 用CSS分隔两个div

javascript - 将 onselectionchange 添加到 vue

javascript - Node.js Express 接收 postman 为空