tidy

清理word文档导出的html中无用的标签。

#-i indent output file
tidy -config tidy-config.txt -o clean.html -i dirty.html
# 一些常见的多余的属性
#\s+class=[^ >]*
#\s+align=[^ >]*
#\s+width=[^ >]*
#\s+valign=[^ >]*
#\s+style='+[^']*'
#\s+style="+[^"]*"
#</?span+\s+[^>]*>
#\s+border=[^ >]*
#\s+cellpadding=[^ >]*
#\s+cellspacing=[^ >]*
# wps导出的HTML文档是采用cp936编码的
# tidy是处理标签的,标签都是英文字母,处理过程使用latin1编码就可以,所以并不需要支持cp936编码的文本
tidy -config tidy-config.txt -i dirty.html | sed -r -e 's/\s+valign=".*"//g' > clean.html
# 可以用iconv转换为utf-8编码
tidy -config tidy-config.txt -i dirty.html |
sed -r -e 's/\s+valign=".*"//g;/<meta/{n;a\<meta charset="utf-8">' -e '}' |
iconv -f cp936 -t utf-8 > clean.html

tidy-config.txt

clean: yes
doctype: html5
word-2000: yes
char-encoding: latin1
bare: yes
drop-empty-paras: yes
drop-proprietary-attributes: yes
enclose-block-text: yes
drop-font-tags: yes
coerce-endtags: yes
join-styles: yes
output-html: yes
error-file: error.txt

results matching ""

    No results matching ""