📄 ubb.cs
字号:
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace bbs.Components
{
/**//// <summary>
/// 功能:UBB代码
/// </summary>
public class UBB
{
#region 构造函数
public UBB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#endregion
#region UBBToHTML
/**//// <summary>
/// UBB代码处理函数
/// </summary>
/// <param name="detail">输入字符串</param>
/// <returns>输出字符串</returns>
public string UBBToHTML(string detail)
{
Regex r;
Match m;
#region 处理[em]标记,处理心情图标
string EmotPath="/bbs/Skins/Default/emot/"; //路径可更改,图片名以em开头
detail = Regex.Replace(detail,@"\[em(.[^\[]*)\]",@"<img src="+EmotPath+"em$1.gif border=0>",RegexOptions.IgnoreCase);
#endregion
#region 处理[IMG][/IMG]标记
detail = Regex.Replace(detail,@"\[IMG\](?<x>[^\]]*)\[\/IMG\]",@"<IMG SRC=""$1"" border=0>",RegexOptions.IgnoreCase);
#endregion
#region 处理html标记
detail = detail.Replace("<","<");
detail = detail.Replace(">",">");
detail = detail.Replace("'","''");
#endregion
#region 处理空格
detail = detail.Replace(" "," ");
#endregion
#region 处理换行
//处理换行,在每个新行的前面添加两个全角空格
r = new Regex(@"(\r\n(( )| )+)(?<正文>\S+)",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),"<BR> " + m.Groups["正文"].ToString());
}
//处理换行,在每个新行的前面添加两个全角空格
detail = detail.Replace("\r\n","<BR>");
//unknown
// sDetail = sDetail.Replace("\r\n","<BR><BR>");
// sDetail = sDetail.Replace("\n","<BR>");
#endregion
#region 处理[b][/b]标记
//方法1
r = new Regex(@"(\[b\])([ \S\t]*?)(\[\/b\])",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),"<B>" + m.Groups[2].ToString() + "</B>");
}
//方法2
// detail = Regex.Replace(detail,@"\[b\](?<x>[^\]]*)\[/b\]",@"<b>$1</b>",RegexOptions.IgnoreCase);
#endregion
#region 处理[i][/i]标记
//方法1
r = new Regex(@"(\[i\])([ \S\t]*?)(\[\/i\])",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),"<I>" + m.Groups[2].ToString() + "</I>");
}
//方法2
// detail = Regex.Replace(detail,@"\[i\](?<x>[^\]]*)\[/i\]",@"<i>$1</i>",RegexOptions.IgnoreCase);
#endregion
#region 处理[U][/U]标记
//方法1
r = new Regex(@"(\[U\])([ \S\t]*?)(\[\/U\])",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),"<U>" + m.Groups[2].ToString() + "</U>");
}
//方法2
// detail = Regex.Replace(detail,@"\[u\](?<x>[^\]]*)\[/u\]",@"<u>$1</u>",RegexOptions.IgnoreCase);
#endregion
#region 处理[p][/p]标记
r = new Regex(@"((\r\n)*\[p\])(.*?)((\r\n)*\[\/p\])",RegexOptions.IgnoreCase|RegexOptions.Singleline);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),"<P class=\"pstyle\">" + m.Groups[3].ToString() + "</P>");
}
#endregion
#region 处理[div][/div]标记
detail = Regex.Replace(detail,@"\[center\](.[^\[]*)\[\/center\]",@"<div align=center>$1</div>",RegexOptions.IgnoreCase);
#endregion
#region 处理[font=xxx][/font]标记
r = new Regex(@"(\[font=([\S]+)\])([ \S\t]*?)(\[\/font\])",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),
"<FONT FACE=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
#region 处理[size=xxx][/size]标记
r = new Regex(@"(\[size=([1-7])\])([ \S\t]*?)(\[\/size\])",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),
"<FONT SIZE=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
#region 处理[color=xxx][/color]标记
r = new Regex(@"(\[color=([\S]+)\])([ \S\t]*?)(\[\/color\])",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),
"<FONT COLOR=" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</FONT>");
}
#endregion
#region 处理[H=x][/H]标记
r = new Regex(@"(\[H=([1-6])\])([ \S\t]*?)(\[\/H\])",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),
"<H" + m.Groups[2].ToString() + ">" +
m.Groups[3].ToString() + "</H" + m.Groups[2].ToString() + ">");
}
#endregion
#region 处理[fly][/fly]标记
detail = Regex.Replace(detail,@"\[fly\](.[^\[]*)\[\/fly\]",@"<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase);
#endregion
#region 处理[move][/move]标记
detail = Regex.Replace(detail,@"\[move\](.[^\[]*)\[\/move\]",@"<marquee scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase);
#endregion
#region 处理[GLOW][/GLOW]标记
detail = Regex.Replace(detail,@"\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/GLOW\]",@"<div style=""width:$1px;filter:glow(color=$2, strength=$3)"">$4</div>",RegexOptions.IgnoreCase);
#endregion
#region 处理[SHADOW][/SHADOW]标记
detail = Regex.Replace(detail,@"\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/SHADOW\]",@"<div style=""width:$1px;filter:shadow(color=$2, strength=$3)"">$4</div>",RegexOptions.IgnoreCase);
#endregion
#region 处理[sup][/sup]标记
r = new Regex(@"(\[sup\])([ \S\t]*?)(\[\/sup\])",RegexOptions.IgnoreCase);
for (m = r.Match(detail); m.Success; m = m.NextMatch())
{
detail = detail.Replace(m.Groups[0].ToString(),"<SUP>" + m.Groups[2].ToString() + "</SUP>");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -