2011-07-09 21 views

回答

2

一种方法,我发现这个代码:

private string CleanHtml(string html) 
{ 
    // start by completely removing all unwanted tags 
    html = Regex.Replace(html, @"<[/]?(font|span|xml|del|ins|[ovwxp]:\w+)[^>]*?>", "", RegexOptions.IgnoreCase); 
    // then run another pass over the html (twice), removing unwanted attributes 
    html = Regex.Replace(html, @"<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^>]+)([^>]*)>","<$1$2>", RegexOptions.IgnoreCase); 
    html = Regex.Replace(html, @"<([^>]*)(?:class|lang|style|size|face|[ovwxp]:\w+)=(?:'[^']*'|""[^""]*""|[^>]+)([^>]*)>","<$1$2>", RegexOptions.IgnoreCase); 
    return html; 
} 

从这里:

Remove Microsoft Class and Style attributes

HTH

+0

不适用于我 –

1

我就遇到了这个问题我自己并找不到一个解决方案,没有删除所有标签和格式。有超过100个条目需要统一的各种样式。我结束了“复位”他们使用CSS:

span{font-family: Arial, Geneva, Helvetica, Verdana !important;font-size: 12px !important;color: #474844 !important;} 

注:这并没有某些特殊字符的帮助,但它确实让所有的风格统一。希望这可以帮助!

相关问题