A good UBB encoding function implemented using JavaScript

Source: Internet
Author: User

Function jsubb (STR)
{
VaR Re = // [I/] (. [^/[] *)/[// I/]/GI;
STR = Str. Replace (Re, "<I> $1 </I>"); // Italic
Re = // [B/] (. [^/[] *)/[// B/]/GI;
STR = Str. Replace (Re, "<B> $1 </B>"); // bold
Re = // [U/] (. [^/[] *)/[// U/]/GI;
STR = Str. Replace (Re, "<u> $1 </u>"); // underline
Re = // [color = (. [^/[] *)/] (. [^/[] *)/[// color/]/GI;
STR = Str. Replace (Re, "<font color = $1> $2 </font>"); // font color
Re = // [size = ([1-7])/] (. [^/[] *)/[// size/]/GI;
STR = Str. Replace (Re, "<font size = $1> $2 </font>"); // font size
Re = // [face = (. [^/[] *)/] (. [^/[] *)/[// face/]/GI;
STR = Str. Replace (Re, "<font face = $1> $2 </font>"); // font

Re = // [center/] (. [^/[] *)/[// center/]/GI;
STR = Str. replace (Re, "

$1
"); // center
Re = // [Right/] (. [^/[] *)/[// right/]/GI;
STR = Str. replace (Re, "
$1
"); // right-aligned
Re = // [quote/] (. [^/[] *)/[// quote/]/GI; // reference
STR = Str. replace (Re, "
$1
");

Re = // [fly/] (. *)/[// fly/]/GI; // flight
STR = Str. Replace (Re, "<marquee width = 90% behavior = alternate scrollamount = 3> $1 </marquee> ");
Re = // [move/] (. *)/[// move/]/GI; // move
STR = Str. Replace (Re, "<marquee scrollamount = 3> $1 </marquee> ");
Re = // [shadow = * ([0-9] *), * (# * [a-z0-9] *), * ([0-9] *)/] (. [^/[] *)/[// shadow]/GI; // shadow
STR = Str. replace (Re, "<Table width = $1> <tr> <TD style = 'filter: Shadow (color = $2, strength = $3) '> $4 </TD> </tr> </table> ");
Re = // [glow = * ([0-9] *), * (# * [a-z0-9] *), * ([0-9] *)/] (. [^/[] *)/[// glow]/GI; // outshines
STR = Str. replace (Re, "<Table width = $1> <tr> <TD style = 'filter: glow (color = $2, strength = $3) '> $4 </TD> </tr> </table> ")

Re = // [url/] (. [^/[] *)/[// URL/]/GI;
STR = Str. Replace (Re, "<a href = '$ 1' target = _ blank> $1 </a>"); // hyperlink 1
Re = // [url = (. [^/[] *)/] (. [^/[] *)/[// URL/]/GI;
STR = Str. Replace (Re, "<a href = '$ 1' target = _ blank> $2 </a>"); // hyperlink 2

Re = // [email/] ([/W-] + (/. [/W-] +) * @ [/W-] + (/. [/W-] +)/[// email/]/GI;
STR = Str. Replace (Re, "<a href = 'mailto: $ 1'> $1 </a>"); // email link 1
Re = // [email = ([/W-] + (/. [/W-] +) * @ [/W-] + (/. [/W-] +)/] (. [^/[] *)/[// email/]/GI;
STR = Str. Replace (Re, "<a href = 'mailto: $ 1'> $4 </a>"); // email link 2

Re = // [img/] (. [^/[] *)/[// img/]/GI;
STR = Str. replace (Re, "<a href = '$ 1' target = _ blank> </> "); // Image
Re =/: EM (/d {1,}):/GI;
STR = Str. Replace (Re, "Return STR;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.