亚洲综合原千岁中文字幕_国产精品99久久久久久久vr_无码人妻aⅴ一区二区三区浪潮_成人h动漫精品一区二区三

主頁 > 知識庫 > C#正則實現Ubb解析類的代碼

C#正則實現Ubb解析類的代碼

熱門標簽:知名的電話機器人 湖南企業智能外呼系統供應商 RO地圖標注app 錫林郭勒盟地圖標注位置 高德地圖標注短信簽約 百音電話機器人 福州工作銷售電話機器人 電銷機器人公司簡介 自制電銷機器人
解析得到的代碼能通過XHTML 1.0 STRICT驗證;
包含了標題,鏈接,字體,對齊,圖片,引用,列表等方面的功能. 
Ubb.ReadMe.htm

[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執行]

復制代碼 代碼如下:

//作者:deerchao 
// http://www.unibetter.com/blogs/blogdeerchao/default.aspx 
//在不移除以上(及本條)注釋的前提下,任何人可以以任何方式使用此代碼. 

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Web; 
using System.Text.RegularExpressions; 

namespace Deerchao.Web 

    public class UbbDecoder 
    { 
        private static readonly RegexOptions options = RegexOptions.Compiled | RegexOptions.Singleline; 

        /// summary> 
        /// 解析Ubb代碼為Html代碼 
        /// /summary> 
        /// param name="ubb">Ubb代碼/param> 
        /// returns>解析得到的Html代碼/returns> 
        public static string Decode(string ubb) 
        { 
            if (string.IsNullOrEmpty(ubb)) 
                return null; 
            string result = ubb; 
            result = HttpUtility.HtmlEncode(result); 

            result = DecodeStyle(result); 
            result = DecodeFont(result); 
            result = DecodeColor(result); 
            result = DecodeImage(result); 
            result = DecodeLinks(result); 
            result = DecodeQuote(result); 
            result = DecodeAlign(result); 
            result = DecodeList(result); 
            result = DecodeHeading(result); 
            result = DecodeBlank(result); 

            return result; 
        } 

        /// summary> 
        /// 解析Ubb代碼為Html代碼,所有的鏈接為rel="nofollow" 
        /// /summary> 
        /// param name="ubb">Ubb代碼/param> 
        /// returns>解析得到的Html代碼/returns> 
        public static string DecodeNoFollow(string ubb) 
        { 
            if (string.IsNullOrEmpty(ubb)) 
                return null; 
            string result = ubb; 
            result = HttpUtility.HtmlEncode(result); 

            result = DecodeStyle(result); 
            result = DecodeFont(result); 
            result = DecodeColor(result); 
            result = DecodeImage(result); 
            result = DecodeLinksNoFollow(result); 
            result = DecodeQuote(result); 
            result = DecodeAlign(result); 
            result = DecodeList(result); 
            result = DecodeHeading(result); 
            result = DecodeBlank(result); 

            return result; 
        } 

        private static string DecodeHeading(string ubb) 
        { 
            string result = ubb; 
            result = Regex.Replace(result, @"\[h(\d)\](.*?)\[/h\1\]", "h$1>$2/h$1>", options); 
            return result; 
        } 

        private static string DecodeList(string ubb) 
        { 
            string sListFormat = "ol style=\"list-style:{0};\">$1/ol>"; 
            string result = ubb; 
            // Lists 
            result = Regex.Replace(result, @"\[\*\]([^\[]*)", "li>$1/li>", options); 
            result = Regex.Replace(result, @"\[list\]\s*(.*?)\[/list\]", "ul>$1/ul>", options); 
            result = Regex.Replace(result, @"\[list=1\]\s*(.*?)\[/list\]", string.Format(sListFormat, "decimal"), options); 
            result = Regex.Replace(result, @"\[list=i\]\s*(.*?)\[/list\]", string.Format(sListFormat, "lower-roman"), options); 
            result = Regex.Replace(result, @"\[list=I\]\s*(.*?)\[/list\]", string.Format(sListFormat, "upper-roman"), options); 
            result = Regex.Replace(result, @"\[list=a\]\s*(.*?)\[/list\]", string.Format(sListFormat, "lower-alpha"), options); 
            result = Regex.Replace(result, @"\[list=A\]\s*(.*?)\[/list\]", string.Format(sListFormat, "upper-alpha"), options); 

            return result; 
        } 

        private static string DecodeBlank(string ubb) 
        { 
            string result = ubb; 

            result = Regex.Replace(result, @"(?= ) | (?= )", "nbsp;", options); 
            result = Regex.Replace(result, @"\r\n", "br />"); 
            string[] blockTags = {"h[1-6]", "li", "list", "div", "p", "ul"}; 
            //clear br before block tags(start or end) 
            foreach (string tag in blockTags) 
            { 
                Regex r = new Regex("br />(" + tag + ")",options); 
                result = r.Replace(result, "$1"); 
                r = new Regex("br />(/" + tag + ")",options); 
                result = r.Replace(result, "$1"); 
            } 
            return result; 
        } 

        private static string DecodeAlign(string ubb) 
        { 
            string result = ubb; 

            result = Regex.Replace(result, @"\[left\](.*?)\[/left\]", "div style=\"text-align:left\">$1/div>", options); 
            result = Regex.Replace(result, @"\[right\](.*?)\[/right\]", "div style=\"text-align:right\">$1/div>", options); 
            result = Regex.Replace(result, @"\[center\](.*?)\[/center\]", "div style=\"text-align:center\">$1/div>", options); 

            return result; 
        } 

        private static string DecodeQuote(string ubb) 
        { 
            string result = ubb; 

            result = Regex.Replace(result, @"\[quote\]", "blockquote>div>", options); 
            result = Regex.Replace(result, @"\[/quote\]", "/div>/blockquote>", options); 
            return result; 
        } 

        private static string DecodeFont(string ubb) 
        { 
            string result = ubb; 

            result = Regex.Replace(result, @"\[size=([-\w]+)\](.*?)\[/size\]", "span style=\"font-size:$1\">$2/span>", options); 
            result = Regex.Replace(result, @"\[font=(.*?)\](.*?)\[/font\]", "span style=\"font-family:$1\">$2/span>", options); 
            return result; 
        } 

        private static string DecodeLinks(string ubb) 
        { 
            string result = ubb; 

            result = Regex.Replace(result, @"\[url\]www\.(.*?)\[/url\]", "a href=\"http://www.$1\">$1/a>", options); 
            result = Regex.Replace(result, @"\[url\](.*?)\[/url\]", "a href=\"$1\">$1/a>", options); 
            result = Regex.Replace(result, @"\[url=(.*?)\](.*?)\[/url\]", "a href=\"$1\" title=\"$2\">$2/a>", options); 
            result = Regex.Replace(result, @"\[email\](.*?)\[/email\]", "a href=\"mailto:$1\">$1/a>", options); 
            return result; 
        } 

        private static string DecodeLinksNoFollow(string ubb) 
        { 
            string result = ubb; 

            result = Regex.Replace(result, @"\[url\]www\.(.*?)\[/url\]", "a rel=\"nofollow\" href=\"http://www.$1\">$1/a>", options); 
            result = Regex.Replace(result, @"\[url\](.*?)\[/url\]", "a rel=\"nofollow\" href=\"$1\">$1/a>", options); 
            result = Regex.Replace(result, @"\[url=(.*?)\](.*?)\[/url\]", "a rel=\"nofollow\" href=\"$1\" title=\"$2\">$2/a>", options); 
            result = Regex.Replace(result, @"\[email\](.*?)\[/email\]", "a href=\"mailto:$1\">$1/a>", options); 
            return result; 
        } 

        private static string DecodeImage(string ubb) 
        { 
            string result = ubb; 

            result = Regex.Replace(result, @"\[hr\]", "hr />", options); 
            result = Regex.Replace(result, @"\[img\](.+?)\[/img\]", "img src=\"$1\" alt=\"\" />", options); 
            result = Regex.Replace(result, @"\[img=(\d+)x(\d+)\](.+?)\[/img\]", "img src=\"$3\" style=\"width:$1px;height:$2px\" alt=\"\" />", options); 

            return result; 
        } 

        private static string DecodeColor(string ubb) 
        { 
            string result = ubb; 
            result = Regex.Replace(result, @"\[color=(#?\w+?)\](.+?)\[/color\]", "span style=\"color:$1\">$2/span>",options); 

            return result; 
        } 

        private static string DecodeStyle(string ubb) 
        { 
            string result=ubb; 
            //we don't need this for perfomance and other consideration: 
            //(table[^>]*>(?>table[^>]*>(?Depth>)|/table>(?-Depth>)|.)+(?(Depth)(?!))/table>) 
            result = Regex.Replace(result, @"\[[b]\](.*?)\[/[b]\]", "strong>$1/strong>", options); 
            result = Regex.Replace(result, @"\[[u]\](.*?)\[/[u]\]", "span style=\"text-decoration:underline\">$1/span>", options); 
            result = Regex.Replace(result, @"\[[i]\](.*?)\[/[i]\]", "i>$1/i>", options); 

            return result; 
        } 
    } 

您可能感興趣的文章:
  • xml 封裝與解析(javascript和C#中)
  • C#解析json文件的實現代碼
  • C#下解析HTML的兩種方法介紹
  • asp.net C#生成和解析二維碼的實例代碼
  • c#實現flv解析詳解示例
  • c#中XML解析文件出錯解決方法
  • C#解析JSON實例
  • C# 解析 Excel 并且生成 Csv 文件代碼分析
  • 用C#來解析PDF文件
  • C#解析Lrc歌詞文件過程詳解

標簽:吉林 玉林 河北 怒江 西寧 茂名 秦皇島 昆明

巨人網絡通訊聲明:本文標題《C#正則實現Ubb解析類的代碼》,本文關鍵詞  正則,實現,Ubb,解析,類,的,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《C#正則實現Ubb解析類的代碼》相關的同類信息!
  • 本頁收集關于C#正則實現Ubb解析類的代碼的相關信息資訊供網民參考!
  • 推薦文章
    尤物视频网站在线| 精品视频在线观看免费| 日韩av成人| 日韩中文字幕一区| 亚洲第一页乱| 欧美国产日韩精品| 一级女性全黄久久生活片| 九九久久国产精品大片| 天天色成人网| 欧美激情一区二区三区在线| 日本免费乱理伦片在线观看2018| 日本伦理片网站| 欧美18性精品| 亚洲精品久久久中文字| 91麻豆精品国产高清在线| 999精品视频在线| 香蕉视频亚洲一级| 欧美电影免费| 99久久精品国产麻豆| 九九久久国产精品大片| 99久久精品国产高清一区二区| 日韩中文字幕一区| 日本特黄特色aaa大片免费| 国产伦理精品| 国产伦久视频免费观看 视频| 日本免费区| 亚洲天堂在线播放| 一级毛片视频在线观看| 精品视频在线看| 国产高清在线精品一区a| 久久久久久久男人的天堂| 99久久精品国产麻豆| 国产欧美精品| 国产不卡精品一区二区三区| 久久国产精品自线拍免费| 成人免费观看网欧美片| 日韩字幕在线| 欧美激情一区二区三区视频高清 | a级毛片免费观看网站| 欧美1区2区3区| 99久久精品国产麻豆| 午夜在线亚洲| 精品国产一区二区三区久| 欧美激情一区二区三区在线| 国产精品自拍一区| 精品视频在线看| 亚洲第一色在线| 国产激情一区二区三区| 成人免费高清视频| 欧美1区2区3区| 精品国产一区二区三区久久久蜜臀 | 欧美一区二区三区在线观看| 亚洲精品影院久久久久久| 国产成人精品影视| 国产一区二区精品尤物| 欧美另类videosbestsex高清| 亚洲第一页乱| 成人高清免费| 欧美激情影院| 尤物视频网站在线| 国产视频一区二区在线观看| 久久久久久久久综合影视网| 欧美激情一区二区三区视频高清 | 二级片在线观看| 日本伦理片网站| 日韩男人天堂| 精品在线观看国产| 九九精品久久久久久久久| 精品国产一区二区三区国产馆| 国产一区免费观看| 欧美电影免费| 午夜家庭影院| 久久精品免视看国产成人2021| 日韩中文字幕一区| 九九干| 日本特黄特色aaa大片免费| 久久福利影视| 欧美激情在线精品video| 国产麻豆精品高清在线播放| 色综合久久天天综合| 日日日夜夜操| 国产不卡精品一区二区三区| 成人a级高清视频在线观看| 人人干人人插| 欧美a免费| 成人免费高清视频| 久久精品店| 一本高清在线| 好男人天堂网 久久精品国产这里是免费 国产精品成人一区二区 男人天堂网2021 男人的天堂在线观看 丁香六月综合激情 | 台湾毛片| 欧美国产日韩一区二区三区| 91麻豆精品国产自产在线观看一区| 美女免费精品视频在线观看| 亚欧视频在线| 精品视频免费看| 一级女人毛片人一女人| 一本高清在线| 欧美一区二区三区在线观看| 精品在线免费播放| 国产网站在线| 久久久成人网| 成人高清视频在线观看| 日韩男人天堂| 日韩中文字幕一区| 青草国产在线观看| 天天色色网| 日韩女人做爰大片| 国产综合成人观看在线| 国产一区二区精品久久91| 国产麻豆精品免费密入口| 久久成人综合网| 成人影视在线观看| 精品视频在线看 | 99色视频在线| 国产精品自拍在线| 香蕉视频久久| 可以免费看污视频的网站| 韩国三级香港三级日本三级| 久久99青青久久99久久| 午夜精品国产自在现线拍| 韩国三级视频网站| 免费的黄视频| 欧美大片一区| 久久99中文字幕久久| 九九干| 美女免费精品视频在线观看| 欧美夜夜骑 青草视频在线观看完整版 久久精品99无色码中文字幕 欧美日韩一区二区在线观看视频 欧美中文字幕在线视频 www.99精品 香蕉视频久久 | 日本免费区| 日韩专区亚洲综合久久| 成人免费高清视频| 久草免费资源| 欧美一级视频高清片| 欧美大片一区| 日韩在线观看视频免费| 国产韩国精品一区二区三区| 精品视频在线观看一区二区| 久久精品欧美一区二区| 国产国语对白一级毛片| 成人a级高清视频在线观看| 精品久久久久久中文字幕2017| 精品视频一区二区| 一级片免费在线观看视频| 青草国产在线观看| 欧美另类videosbestsex高清| 成人免费高清视频| 欧美激情在线精品video| 台湾毛片| 欧美激情影院| 999精品在线| 精品国产亚洲一区二区三区| 国产成人精品影视| 久久99青青久久99久久| 超级乱淫伦动漫| 四虎久久精品国产| 亚洲精品永久一区| 九九九网站| 天天做日日爱夜夜爽| 久久国产影视免费精品| 国产麻豆精品| 美女免费精品视频在线观看| 精品在线免费播放| 成人a级高清视频在线观看| 久久精品店| 日韩专区亚洲综合久久| 999久久狠狠免费精品| 国产91精品系列在线观看| 精品视频在线观看一区二区| 亚欧视频在线| 国产伦精品一区二区三区在线观看 | 91麻豆国产| 国产成+人+综合+亚洲不卡 | 欧美另类videosbestsex久久 | 黄色短视屏| 久久国产影视免费精品| 日本免费区| 日本免费乱理伦片在线观看2018| 91麻豆精品国产自产在线观看一区| 日韩中文字幕一区| 国产一区二区精品尤物| 成人高清免费| 麻豆污视频| 日本在线播放一区| 国产极品白嫩美女在线观看看| 尤物视频网站在线| 国产一区二区福利久久| 日日日夜夜操| 欧美激情在线精品video| 九九久久国产精品大片| 欧美激情一区二区三区视频 | 日韩中文字幕在线亚洲一区| 欧美激情一区二区三区在线| 九九干| 久久精品欧美一区二区| 一级毛片视频在线观看| 你懂的日韩| 国产不卡在线观看视频| 久久国产精品永久免费网站| 国产网站免费在线观看| 午夜久久网| 精品久久久久久免费影院|