您的位置:首页 > Web前端 > CSS

清除WORD格式HTML垃圾样式

2008-08-21 16:00 501 查看
static string CleanWordHtml(string html)
{
StringCollection sc = new StringCollection();
// get rid of unnecessary tag spans (comments and title)
sc.Add(@"<!--(/w|/W)+?-->");
sc.Add(@"<title>(/w|/W)+?</title>");
// Get rid of classes and styles
sc.Add(@"/s?class=/w+");
sc.Add(@"/s+style='[^']+'");
// Get rid of unnecessary tags
//sc.Add(@"<(meta|link|/?o:|/?style|/?div|/?st/d|/?head|/?html|body|/?body|/?span|!/[)[^>]*?>");
sc.Add(@"<(meta|link|/?o:|/?style|/?font|/?strong|/?st/d|/?head|/?html|body|/?body|/?span|!/[)[^>]*?>");
// Get rid of empty paragraph tags
sc.Add(@"(<[^>]+>)+ (<//w+>)+");
// remove bizarre v: element attached to <img> tag
sc.Add(@"/s+v:/w+=""[^""]+""");
// remove extra lines
sc.Add(@"(/n/r){2,}");
foreach (string s in sc)
{
html = Regex.Replace(html, s, "", RegexOptions.IgnoreCase);
}
return html;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: