使用HTML Tidy缩进<head>和<body>

时间:2019-08-02 23:19:22

标签: html macos command-line htmltidy

我要缩进

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <ul>
        <li>List 1</li>
        <li>List 2</li>
        <li>List 3</li>
        <li>List 4</li>
        <li>List 5</li>
    </ul>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <ul>
            <li>List 1</li>
            <li>List 2</li>
            <li>List 3</li>
            <li>List 4</li>
            <li>List 5</li>
        </ul>
    </body>
</html>

tidy -config config.txt -m index.html

config.txt看起来像

doctype: html5
indent: auto
indent-spaces: 4
wrap: 0
tab-size: 4
quiet: yes
show-warnings: no
tidy-mark: no

版本为:HTML Tidy for Apple macOS version 5.6.0

我浏览了HTML Tidy 5.7.0 Options Quick Reference并尝试了一些尝试,但没有成功。

缺少什么?

1 个答案:

答案 0 :(得分:0)

“问题”是您的选择onDeviceReady。在man pages中,您可以阅读:

indent: auto

If set to auto Tidy will decide whether or not to indent the content of tags such as <title>, <h1>-<h6>, <li>, <td>, or <p> based on the content including a block- level element. 设置为indent时,您的yes<head>部分将缩进,但所有列表项也将缩进,

>
<body>

仅供参考:您无需将<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> Document </title> </head> <body> <ul> <li>List 1 </li> <li>List 2 </li> <li>List 3 </li> <li>List 4 </li> <li>List 5 </li> </ul> </body> </html> 的所有选项都写入配置文件中,还可以通过在每个选项前面加上tidy并以空格分隔的值来将它们作为选项传递。产生以上输出的最小命令是:

--

在某些情况下可能有用。