ComplianceServer/oldcode/Core.Common/TextHelper.cs

63 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace CRM.Core.Common
{
public class TextHelper
{
/// <summary>
/// 标签加注释
/// </summary>
/// <param name="html"></param>
/// <returns></returns>
public static string Encode(string html, bool bIgnoreFont = false, bool bRemoveStyles = false, bool cleanWordKeepsStructure = true)
{
if (string.IsNullOrEmpty(html)) return html;
html = html.Replace("[#--", "<!--[#--");
html = html.Replace("--#]", "--#]-->");
html = ClearScript(html);
//html = DomainEncode(htmlReplace.ClearScript(html));
return html;
}
public static string ClearScript(string Htmlstring) //替换HTML标记
{
if (Htmlstring == null)
return Htmlstring;
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>[\s\S]*?</script>", "", RegexOptions.IgnoreCase);
return Htmlstring;
}
/* /// <summary>
/// 替换域名加密
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string DomainEncode(string text, bool ishtt = false)
{
if (string.IsNullOrEmpty(text)) return text;
if (ishtt)
{
text = text.Replace("http:", "");
text = text.Replace("https:", "");
}
text = text.Replace("mediadatabucket.oss-cn-shanghai.aliyuncs.com", "v.cdn.dn8188.com");
text = text.Replace(_imgUrl, _UploadFilePath);
//当前怕布置项目到其它地方出问题,特意写如此临时判断
text = text.Replace("//img.cdn.dn8188.com", _UploadFilePath);
text = text.Replace("//img.hc.dn8188.com", _UploadFilePath);
text = text.Replace(_cmsUrl, _cmsUrlEncodeKey);
text = text.Replace(_softUrl, _softUrlEncodeKey);
return text;
}*/
}
}