如何使用Tidy从HTML中删除所有属性和类?

4

I have a lot of HTML files such as:

<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt">some text</P>
<TABLE class=MsoNormalTable style="BORDER-RIGHT: windowtext 1pt solid;" cellSpacing=0 cellPadding=0 width=568 border=1>
<TR style="HEIGHT: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes">
<TD style="BORDER-RIGHT: windowtext 1pt solid;" width=357 colSpan=2>text td</TD>
</TR>
</TABLE>

我需要将其所有属性和类都移除,以便得到以下结果:
<P>some text</P>
<TABLE>
<TR>
<TD>text td</TD>
</TR>
</TABLE>

我已经尝试使用不同选项的 tidy 工具(如 drop-proprietary-attributes、word-2000),但无法得到干净的代码。


你应该避免在元素标记内设置元素样式。这种方式很难维护。请使用 <style></style> 标记。 - gabriel garcia
2
你说得对。但是我的任务现在只是清理旧代码。 - Dimetry
1个回答

0

这将删除所有 MS 样式:

tidy --word-2000 true --bare true -o output.html input.htm 

我使用的是“HTML Tidy for Linux版本5.1.25”


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接