Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

HTML to UBB code

Description
Converts HTML formatting to UBB (bulletin/message board) formatting.
Language
C#.net
Minimum Version
Created By
小恐龙
Contributors
-
Date Created
Aug 1, 2017
Date Last Modified
Aug 1, 2017

Macro Code

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

//小恐龙
//ver 1.0
// 转换 html 代码为论坛常用的 ubb 代码.

public static class ClipboardFusionHelper
{
	public static string ProcessText(string text)
	{
        text = Regex.Replace(text, "<br[^>]*>", "\n");
        text = Regex.Replace(text, @"<p[^>\/]*\/>", "\n");
        text = Regex.Replace(text, "\\son[\\w]{3,16}\\s?=\\s*([\'\"]).+?\\1", "");
        text = Regex.Replace(text, "<hr[^>]*>", "[hr]");

        text = Regex.Replace(text, "<(\\/)?blockquote([^>]*)>", "[$1blockquote]");
        text = Regex.Replace(text, "<img[^>]*smile=\"(\\d+)\"[^>]*>", "'[s:$1]");
        text = Regex.Replace(text, "<img[^>]*src=[\'\"\\s]*([^\\s\'\"]+)[^>]*>", "");
        text = Regex.Replace(text, "<a[^>]*href=[\'\"\\s]*([^\\s\'\"]*)[^>]*>(.+?)<\\/a>", "[url=$1]$2[/url]");
        text = Regex.Replace(text, "<b>(.+?)</b>",@"\[b\]$1\[/b\]");
        text = Regex.Replace(text, "<[^>]*?>", "");
        text = Regex.Replace(text, "&", "&");
        text = Regex.Replace(text, " ", " ");
        text = Regex.Replace(text, "<", "<");
        text = Regex.Replace(text, ">", ">");

		return text;
	}
}