PDA

View Full Version : BBCode like text parsing


HnathBST
09-17-2013, 05:11 AM
I created a little plugin that will parse SOME bbcodes (at the moment I've only been focusing on the popup window, chat will come next.)

text_parse.pl

sub ParseText
{
my $text = $_[0];
$text =~ s!\+)\]([^\[\]]+)\!plugin::PWColor("$1")."$2</c>"!gie;
$text =~ s!\{6})\]([^\[\]]+)\[/color\]!<c \"$1\" >$2</c>!gi;
$text =~ s!\[link=([\w|:|/|\.|\?|#|-]+)\]([^\[\]]+)\[/link\]!<a href=\"$1\">$2</a>!gi;
$text =~ s!\[br\]!<br />!gi;
$text =~ s!\[hr\]!plugin::PWBreak()!gie;
$text =~ s!^\([^\[\]]+)\[/center\]!plugin::PWAutoCenter($1)."<br />";!gie;
$text =~ s!\[center\]([^\[\]]+)\[/center\]!plugin::PWAutoCenter($1)."<br />";!gie;

return $text;
}


to use in a quest:

sub EVENT_SAY
{
if($text =~ /hail/i){
my $popup = "[*center]Look ma, I'm centering... and then the sky went [*color=Red]red [br] you can see [*color=#FF0066]more[/color] here [hr]";
quest::popup("Text Parse Test:",plugin::ParseText($popup));
}
}

take the * out of the color= box and center ( otherwise it changes the color on the forums >.< )
This would result in:
http://prntscr.com/1rsrpx

Currently supported bbcodes are link,center,color (by name & hex),br & hr

you can change colors inside a center but you can't color a center...

Akkadius
04-18-2014, 09:03 PM
This is interesting. You came out with this just a little after I created:

http://wiki.eqemulator.org/p?The_DiaWind_Plugin&frm=Perl_Plugins_Master_Reference

Do you want this added?