Yuck. Below is a script that i used recently to script out a lot of word-generated junk .. caveat emptor--it was a quick & dirty solution for my specific files. But some of the regex's maybe of some use. Note that it gets rid of everything inbetween <!...> tags, and also pretty much strips also style junk with mso in it.
Usage: cleanWord.pl infile > outfile
#!/usr/bin/perl -p0777
s#<!--.*?-->##sg;
s#<!\[if .*?\]>(.*?(?!<!).*?)<!\[endif\](--)?>##sg;
s#<o:p></o:p>##sg;
s#<span\s+style='(?:(?:mso-bidi-)?font-size:\d+\.\d+pt;\s*)?font-famil
+y:Arial'>([^<]*)</span>#$1#sg;
s#<ol start=1 type=1>#<ol>#sg;
s#<li[^>]+>#<li>#sg;
s#<span\s+style='(?:(?:mso-bidi-)?font-size:\d+\.\d+pt;\s*)?font-famil
+y:Arial'>#<span>#sg;
s#<span\s+style="mso-spacerun:\s*yes">#<span>#sg;
s#<b style='mso-bidi-font-weight:\s*normal'>#<b>#sg;
s#<p[^>]*?>#<p>#sg;
s#<span[^>]*?>(.*?(?!span).*?)</span>#$1#sg;
s#<span>(.*?(?!span).*?)</span>#$1#sg;
# s#(<img.*?src=")[^>]+/[^>]+\.([^\.>]+?)(">)#sprintf("%simage%04d.%s%
+s",$1,++$N,$2,$3)#sge;
s#(<img.*?\s+)id="\S+"([^>]*?>)#$1$2#sg;
s#class=section#class="Section"#sg;
As for a more generic approach, I haven't used one, but a quick cpan search or HTML yields HTML::Scrubber and HTML::Sanitizer which (at a 2-s glance) look promising.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|