整理添加太多新行

时间:2015-05-13 21:00:34

标签: html html5 tidy htmltidy

我很狡猾,我正在尝试格式化一些HTML文件。我有一个看起来像的部分:

<table>
    <tr><th class="x">Some stuff:</th><th class="x"><span class="y">{{qwe}}</span></th></tr>
    <tr><th class="x">Some more stuff:</th><th class="x">{{rty}}</th></tr>
    <tr><th class="x">Thing 1 / thing 2 / thing 3:</th><th class="x">{{asd}} / {{fgh}} / {{poi}}</th></tr>
    <tr><th class="x">Some file name:</th><th class="x"><a href="{{lkj}}" target="_blank">{{mnb}}</a></th></tr>
</table>

我创建了这个整洁的配置文件:

vertical-space: no
wrap: 0
new-blocklevel-tags: section, header
sort-attribute: alpha

我在文件上运行tidy -config ~/tidy-config.txt -m myfile.html,上面的部分格式如下:

<table>
  <tr>
    <th class="x">Some stuff:</th>

    <th class="x"><span class="y">{{qwe}}</span></th>
  </tr>

  <tr>
    <th class="x">Some more stuff:</th>

    <th class="x">{{rty}}</th>
  </tr>

  <tr>
    <th class="x">Thing 1 / thing 2 / thing 3:</th>

    <th class="x">{{asd}} / {{fgh}} / {{poi}}</th>
  </tr>

  <tr>
    <th class="x">Some file name:</th>

    <th class="x"><a href="{{lkj}}" target="_blank">{{mnb}}</a></th>
  </tr>
</table>

我喜欢每个<th>标记在不同的行上分割,但我不喜欢所有额外的换行符。总的来说,这看起来比原来更糟糕,因为它太稀疏了!有没有办法有一个更紧凑的漂亮印刷?或者设置哪些标签在关闭后得到换行符?我挖了配置选项但找不到任何有用的东西。

修改

我喜欢这样的事情:

<table>
  <tr>
    <th class="x">Some stuff:</th>
    <th class="x"><span class="y">{{qwe}}</span></th>
  </tr>
  <tr>
    <th class="x">Some more stuff:</th>
    <th class="x">{{rty}}</th>
  </tr>
  <tr>
    <th class="x">Thing 1 / thing 2 / thing 3:</th>
    <th class="x">{{asd}} / {{fgh}} / {{poi}}</th>
  </tr>
  <tr>
    <th class="x">Some file name:</th>
    <th class="x"><a href="{{lkj}}" target="_blank">{{mnb}}</a></th>
  </tr>
</table>

无论如何,如果您可以建议使用其他工具,请执行此操作。

1 个答案:

答案 0 :(得分:1)

indent设为true

indent: true
indent-spaces: 2
vertical-space: no
wrap: 0
new-blocklevel-tags: section, header
sort-attributes: alpha

你会给你这个输出

<table>
  <tr>
    <th class="x">
      Some stuff:
    </th>
    <th class="x">
      <span class="y">{{qwe}}</span>
    </th>
  </tr>
  <tr>
    <th class="x">
      Some more stuff:
    </th>
    <th class="x">
      {{rty}}
    </th>
  </tr>
  <tr>
    <th class="x">
      Thing 1 / thing 2 / thing 3:
    </th>
    <th class="x">
      {{asd}} / {{fgh}} / {{poi}}
    </th>
  </tr>
  <tr>
    <th class="x">
      Some file name:
    </th>
    <th class="x">
      <a href="{{lkj}}" target="_blank">{{mnb}}</a>
    </th>
  </tr>
</table>