You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何更好控制HTML自动缩进?含Tidy工具使用场景

HTML Tidy 属性对齐优化方案
  • 自定义配置文件实现属性对齐
    创建一个tidy.config配置文件,写入以下规则:

    indent-attributes: yes
    attribute-indent: 4
    wrap-attributes: yes
    wrap-attribute-indent: 4
    

    执行命令时指定该配置文件:

    tidy -config tidy.config -qni -ashtml index.html -o out.html
    

    其中:

    • indent-attributes: yes 开启属性缩进功能
    • attribute-indent: 4 设置属性相对于标签名的缩进空格数
    • wrap-attributes: yes 强制每个属性单独占用一行
    • wrap-attribute-indent: 4 设置换行后属性的缩进量
  • 直接通过命令行参数添加对齐规则
    无需配置文件,直接在原有命令中补充属性对齐相关参数:

    tidy -qni -ashtml -indent-attributes yes -attribute-indent 4 -wrap-attributes yes -wrap-attribute-indent 4 index.html -o out.html
    
  • 版本兼容说明
    HTML Tidy 5.6.0完全支持上述参数,且与你当前使用的-qni(安静模式+缩进)参数无冲突,可以直接组合使用。

内容的提问来源于stack exchange,提问作者user3313834

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 15:37:32