使用asp.net在数据库中保存richtext编辑器文本时删除内联样式

Remove inline style when saving richtext editor text in database using asp.net

本文关键字:文本 删除 样式 编辑器 richtext net asp 数据库 保存 使用      更新时间:2023-09-26

我正在使用jquery richtext编辑器,是否有一种方法可以删除所有的richtext编辑器添加的内联样式,因为一些用户正在添加自己的样式并破坏布局。

有没有办法使用jquery或c#

我找到了这段代码:

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;
}
从这里

:

删除Microsoft Class和Style属性

HTH

我自己遇到了这个问题,找不到一个不删除所有标签和格式的解决方案。有超过100个参赛作品,各种各样的风格都需要统一。最后我用CSS"重置"了它们:

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

注意:这对某些特殊字符没有帮助,但它确实使所有样式统一。希望这对你有帮助!