package HTML::BBCode; use strict; use warnings; sub new { my $class = shift; my $self = {}; bless($self, $class); $self->_init(@_); return $self; } sub _init { my $self = shift; my %attr = @_; my %tags = ( b => '%s', i => '%s', u => '%s', center => '
$1<\/p>\n/g; for (keys %{$self->{allowedTags}}) { $text =~ s{ \[$_\](.+?)\[/$_\] } { _replace($self,$_,$1) }egsx; $text =~ s{ \[($_)=([a-zA-Z_0-9\#]+)\](.+?)\[/$_\] } { _replace($self,$1,$2,$3) }egsx; } return $text; } sub _replace { my $self = shift; return sprintf($self->{allowedTags}->{shift(@_)}, @_); } sub escape_html { my $text = shift; $text =~ s/&/&/gso; $text =~ s/</gso; $text =~ s/>/>/gso; return $text; } 1;