UBB编辑器(路过请进)
最近本人写了一个简单的UBB编辑器,其中每个标签的功能单独都能完成,而且在对齐、字体加粗、斜体、飞行、移动等功能组合起来也能实现,
最近本人写了一个简单的UBB编辑器,其中每个标签的功能单独都能完成,而且在对齐、字体加粗、斜体、飞行、移动等功能组合起来也能实现,但很怪的是唯独发光和阴影和飞行、移动、对齐组合起来就不能同时实现了(发光和阴影和字体加粗等组合能实现),本人想了很久实在是想不出其中原由,UBB部分代码如下,请各们高手指正。
1
public string UBBToHTML(string sDetail)
2
{
3
Regex r;
4
Match m;
5
处理空格#region 处理空格
6
sDetail = sDetail.Replace(" "," ");
7
#endregion
8
html标记符#region html标记符
9
sDetail = sDetail.Replace("<","<");
10
sDetail = sDetail.Replace(">",">");
11
#endregion
12
处[B][/B]标记#region 处[B][/B]标记
13
r = new Regex(@"(\[B\])([ \S\t]*?)(\[\/B\])",RegexOptions.IgnoreCase);
14
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
15
{
16
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<B>" + m.Groups[2].ToString() + "</B>");
17
}
18
#endregion
19
处[I][/I]标记#region 处[I][/I]标记
20
r = new Regex(@"(\[I\])([ \S\t]*?)(\[\/I\])",RegexOptions.IgnoreCase);
21
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
22
{
23
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<I>" + m.Groups[2].ToString() + "</I>");
24
}
25
#endregion
26
处[U][/U]标记#region 处[U][/U]标记
27
r = new Regex(@"(\[U\])([ \S\t]*?)(\[\/U\])",RegexOptions.IgnoreCase);
28
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
29
{
30
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<U>" + m.Groups[2].ToString() + "</U>");
31
}
32
#endregion
33
//处[URL=xxx][/URL]标记#region //处[URL=xxx][/URL]标记
34
r = new Regex(@"(\[URL=([ \S\t]+)\])([ \S\t]*?)(\[\/URL\])",RegexOptions.IgnoreCase);
35
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
36
{
37
sDetail = sDetail.Replace(m.Groups[0].ToString(),
38
"<A href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/url.gif\">" +
39
m.Groups[3].ToString() + "</A>");
40
}
41
#endregion
42
处理飞行文字#region 处理飞行文字
43
r = new Regex(@"(\[FLY\])(.[^\[]*)(\[\/FLY\])", RegexOptions.IgnoreCase);
44
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
45
{
46
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<marquee width=90% behavior=alternate scrollamount=3>" + m.Groups[2].ToString() + "</marquee>");
47
}
48
#endregion
49
处理移动文字#region 处理移动文字
50
sDetail = Regex.Replace(sDetail, @"\[move\](.[^\[]*)\[\/move\]", @"<marquee scrollamount=3>$1</marquee>", RegexOptions.IgnoreCase);
51
#endregion
52
//处理[SHADOW][/SHADOW]#region //处理[SHADOW][/SHADOW]
53
sDetail = Regex.Replace(sDetail, @"\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/SHADOW\]", @"<div style=""width:$1px;filter:shadow(color=$2, strength=$3)"">$4</div>", RegexOptions.IgnoreCase);
54
#endregion
55
//处理[GLOW][/GLOW]#region //处理[GLOW][/GLOW]
56
sDetail = Regex.Replace(sDetail, @"\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/GLOW\]", @"<div style=""width:$1px;filter:glow(color=$2, strength=$3)"">$4</div>", RegexOptions.IgnoreCase);
57
#endregion
58
处[EMAIL=xxx][/EMAIL]标记#region 处[EMAIL=xxx][/EMAIL]标记
59
//处[EMAIL=xxx][/EMAIL]标记
60
r = new Regex(@"(\[EMAIL=([ \S\t]+)\])([ \S\t]*?)(\[\/EMAIL\])", RegexOptions.IgnoreCase);
61
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
62
{
63
sDetail = sDetail.Replace(m.Groups[0].ToString(),
64
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +
65
m.Groups[3].ToString() + "</A>");
66
}
67
#endregion
68
处理图片链接#region 处理图片链接
69
//处理图片链接
70
r = new Regex(@"(\[IMG\])([ \S\t]*?)(\[\/IMG\])", RegexOptions.IgnoreCase);
71
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
72
{
73
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<img style=\"cursor:hand\" src=\"" + m.Groups[2].ToString() + "\" border=0 alt=\"点击在新窗口中浏览原始图片!\" onclick=\"javascript:window.open('" + m.Groups[2].ToString() + "')\" onload=\"if(this.height>" + 100 + "||this.width>" + 100 + ")
{if((this.height/" + 100+ ")>(this.width/" + 100 + "))
{this.height=" + 100 + "}else
{this.width=" +100 + "}}\" >");
74
}
75
#endregion
76
处理表情#region 处理表情
77
for (int i = 0; i <= 29; i++)
78
{
79
sDetail = sDetail.Replace("[FACE" + i + "]", "<img border=0 width=40 height=40 SRC=face/face" + i + ".gif>");
80
}
81
#endregion
82
处理[align=x][/align]#region 处理[align=x][/align]
83
//处理[align=x][/align]
84
r = new Regex(@"(\[align=([\S]+)\])([ \S\t]*?)(\[\/align\])",RegexOptions.IgnoreCase);
85
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
86
{
87
sDetail = sDetail.Replace(m.Groups[0].ToString(),
88
"<P align=" + m.Groups[2].ToString() + ">" +
89
m.Groups[3].ToString() + "</P>");
90
}
91
#endregion
92
93
处理换行#region 处理换行
94
//处理换行,在每个新行的前面添加两个全角空格
95
r = new Regex(@"(\r\n(( )| )+)(?<正文>\S+)",RegexOptions.IgnoreCase);
96
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())
97
{
98
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<BR>" + m.Groups["正文"].ToString());
99
}
100
//处理换行,在每个新行的前面添加两个全角空格
101
sDetail = sDetail.Replace("\r\n","<BR>");
102
#endregion
103
return sDetail;
104
}
public string UBBToHTML(string sDetail)2

{3
Regex r;4
Match m;5

处理空格#region 处理空格6
sDetail = sDetail.Replace(" "," ");7
#endregion8

html标记符#region html标记符9
sDetail = sDetail.Replace("<","<");10
sDetail = sDetail.Replace(">",">");11
#endregion12

处[B][/B]标记#region 处[B][/B]标记13
r = new Regex(@"(\[B\])([ \S\t]*?)(\[\/B\])",RegexOptions.IgnoreCase);14
for (m = r.Match(sDetail); m.Success; m = m.NextMatch()) 15

{16
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<B>" + m.Groups[2].ToString() + "</B>");17
}18
#endregion19

处[I][/I]标记#region 处[I][/I]标记20
r = new Regex(@"(\[I\])([ \S\t]*?)(\[\/I\])",RegexOptions.IgnoreCase);21
for (m = r.Match(sDetail); m.Success; m = m.NextMatch()) 22

{23
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<I>" + m.Groups[2].ToString() + "</I>");24
}25
#endregion26

处[U][/U]标记#region 处[U][/U]标记27
r = new Regex(@"(\[U\])([ \S\t]*?)(\[\/U\])",RegexOptions.IgnoreCase);28
for (m = r.Match(sDetail); m.Success; m = m.NextMatch()) 29

{30
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<U>" + m.Groups[2].ToString() + "</U>");31
}32
#endregion33

//处[URL=xxx][/URL]标记#region //处[URL=xxx][/URL]标记34
r = new Regex(@"(\[URL=([ \S\t]+)\])([ \S\t]*?)(\[\/URL\])",RegexOptions.IgnoreCase);35
for (m = r.Match(sDetail); m.Success; m = m.NextMatch()) 36

{37
sDetail = sDetail.Replace(m.Groups[0].ToString(),38
"<A href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/url.gif\">" +39
m.Groups[3].ToString() + "</A>");40
}41
#endregion42

处理飞行文字#region 处理飞行文字43
r = new Regex(@"(\[FLY\])(.[^\[]*)(\[\/FLY\])", RegexOptions.IgnoreCase);44
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())45

{46
sDetail = sDetail.Replace(m.Groups[0].ToString(), "<marquee width=90% behavior=alternate scrollamount=3>" + m.Groups[2].ToString() + "</marquee>");47
}48
#endregion49

处理移动文字#region 处理移动文字50
sDetail = Regex.Replace(sDetail, @"\[move\](.[^\[]*)\[\/move\]", @"<marquee scrollamount=3>$1</marquee>", RegexOptions.IgnoreCase);51
#endregion52

//处理[SHADOW][/SHADOW]#region //处理[SHADOW][/SHADOW]53
sDetail = Regex.Replace(sDetail, @"\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/SHADOW\]", @"<div style=""width:$1px;filter:shadow(color=$2, strength=$3)"">$4</div>", RegexOptions.IgnoreCase);54
#endregion55

//处理[GLOW][/GLOW]#region //处理[GLOW][/GLOW]56
sDetail = Regex.Replace(sDetail, @"\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/GLOW\]", @"<div style=""width:$1px;filter:glow(color=$2, strength=$3)"">$4</div>", RegexOptions.IgnoreCase);57
#endregion58

处[EMAIL=xxx][/EMAIL]标记#region 处[EMAIL=xxx][/EMAIL]标记59
//处[EMAIL=xxx][/EMAIL]标记60
r = new Regex(@"(\[EMAIL=([ \S\t]+)\])([ \S\t]*?)(\[\/EMAIL\])", RegexOptions.IgnoreCase);61
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())62

{63
sDetail = sDetail.Replace(m.Groups[0].ToString(),64
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +65
m.Groups[3].ToString() + "</A>");66
}67
#endregion68

处理图片链接#region 处理图片链接69
//处理图片链接70
r = new Regex(@"(\[IMG\])([ \S\t]*?)(\[\/IMG\])", RegexOptions.IgnoreCase);71
for (m = r.Match(sDetail); m.Success; m = m.NextMatch())72
{73

sDetail = sDetail.Replace(m.Groups[0].ToString(), "<img style=\"cursor:hand\" src=\"" + m.Groups[2].ToString() + "\" border=0 alt=\"点击在新窗口中浏览原始图片!\" onclick=\"javascript:window.open('" + m.Groups[2].ToString() + "')\" onload=\"if(this.height>" + 100 + "||this.width>" + 100 + ")
{if((this.height/" + 100+ ")>(this.width/" + 100 + "))
{this.height=" + 100 + "}else
{this.width=" +100 + "}}\" >");74
}75
#endregion76

处理表情#region 处理表情77
for (int i = 0; i <= 29; i++)78

{79
sDetail = sDetail.Replace("[FACE" + i + "]", "<img border=0 width=40 height=40 SRC=face/face" + i + ".gif>");80
}81
#endregion82

处理[align=x][/align]#region 处理[align=x][/align]83
//处理[align=x][/align]84
r = new Regex(@"(\[align=([\S]+)\])([ \S\t]*?)(\[\/align\])",RegexOptions.IgnoreCase);85
for (m = r.Match(sDetail); m.Success; m = m.NextMatch()) 86

{87
sDetail = sDetail.Replace(m.Groups[0].ToString(),88
"<P align=" + m.Groups[2].ToString() + ">" + 89
m.Groups[3].ToString() + "</P>");90
}91
#endregion92
93

处理换行#region 处理换行94
//处理换行,在每个新行的前面添加两个全角空格95
r = new Regex(@"(\r\n(( )| )+)(?<正文>\S+)",RegexOptions.IgnoreCase);96
for (m = r.Match(sDetail); m.Success; m = m.NextMatch()) 97

{98
sDetail = sDetail.Replace(m.Groups[0].ToString(),"<BR>" + m.Groups["正文"].ToString());99
}100
//处理换行,在每个新行的前面添加两个全角空格101
sDetail = sDetail.Replace("\r\n","<BR>");102
#endregion103
return sDetail;104
}
浙公网安备 33010602011771号