使用HTML Tidy来缩进HTML代码? [英] Use HTML Tidy to just indent HTML code?

查看:269
本文介绍了使用HTML Tidy来缩进HTML代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用HTML Tidy缩进HTML代码?

示例代码

 < form action =? method =getaccept-charset =utf-8> 

< ul>
< li>
< label class =screenReaderfor =q>关键字< / label>< input type =textname =qvalue =id =q/>
< / li>
< li>< input class =submittype =submitvalue =Search/>< / li>
< / ul>


< / form>

预期结果

 < form action =? method =getaccept-charset =utf-8> 
< ul>
< li>
< label class =screenReaderfor =q>关键字< / label>< input type =textname =qvalue =id =q/>
< / li>
< li>< input class =submittype =submitvalue =Search/>< / li>
< / ul>
< / form>

如果我使用标准命令运行它, tidy -f errs.txt -m index.html 然后我得到这个

 <!DOCTYPE html PUBLIC -  // W3C // DTD HTML 4.01 // EN> 
< html>
< head>
适用于Mac OS X的HTML Tidy(2006年10月31日版 - Apple Inc. build 15.3.6),请参阅www.w3.org>
< title>< / title>
< / head>
< body>
< ul>
< li>< label class =screenReaderfor =
q>关键字< / label>< input type =textname =qvalue =id =
q>< / li>
< li>< input class =submittype =submitvalue =Search>< / li>
< / ul>
< / form>
< / body>
< / html>

我怎样才能省略所有额外的东西,然后真正让它缩进代码? / strong>



原谅我,如果这不是它应该支持的功能,我在找什么库/工具?

解决方案使用配置文件,只需缩进 tidy-mark quiet 选项:

 缩进:auto 
indent-spaces:2
quiet:是
tidy-mark:no

将它命名为 tidy_config.txt 并将其保存在与.html文件相同的目录中。像这样运行它:

  tidy -config tidy_config.txt index.html 

如需更多自订,请使用整洁的手册页来查找其他相关选项,例如标记:否强制输出:是

Is it possible to use HTML Tidy to just indent HTML code?

Sample Code

<form action="?" method="get" accept-charset="utf-8">

<ul>
<li>
<label class="screenReader" for="q">Keywords</label><input type="text" name="q" value="" id="q" />
</li>
<li><input class="submit" type="submit" value="Search" /></li>
</ul>


</form>

Desired Result

<form action="?" method="get" accept-charset="utf-8">
    <ul>
        <li>
        <label class="screenReader" for="q">Keywords</label><input type="text" name="q" value="" id="q"/>
        </li>
        <li><input class="submit" type="submit" value="Search"/></li>
    </ul>
</form>

If I run it with the standard command, tidy -f errs.txt -m index.html then I get this

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 15.3.6), see www.w3.org">
<title></title>
</head>
<body>
<form action="?" method="get" accept-charset="utf-8">
<ul>
<li><label class="screenReader" for=
"q">Keywords</label><input type="text" name="q" value="" id=
"q"></li>
<li><input class="submit" type="submit" value="Search"></li>
</ul>
</form>
</body>
</html>

How can I omit all the extra stuff and actually get it to indent the code?

Forgive me if that's not a feature that it's supposed to support, what library / tool am I looking for?

解决方案

Use a config file with just the indent, tidy-mark, and quiet options:

indent: auto
indent-spaces: 2
quiet: yes
tidy-mark: no

Name it tidy_config.txt and save it the same directory as the .html file. Run it like this:

tidy -config tidy_config.txt index.html

For more customization, use the tidy man page to find other relevant options such as markup: no or force-output: yes.

这篇关于使用HTML Tidy来缩进HTML代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆