The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

BBCode::Parser - Parses BBCode tags

DESCRIPTION

BBCode is a simplified markup language used in several online forums and bulletin boards. It originated with phpBB, and remains most popular among applications written in PHP. Generally, users author their posts in BBCode, and the forum converts it to a permitted subset of well-formed HTML.

BBCode::Parser is a proper recursive parser for BBCode-formatted text.

METHODS

new

        my $parser = BBCode::Parser->new(%args);

new creates a new BBCode::Parser. Any arguments are handed off to the "set" method.

get

        if($parser->get('foo')) {
                # Foo enabled
        } else {
                # Foo disabled
        }

get returns settings for the given parser.

set

        $parser->set(foo => 1);

set alters settings for the given parser.

permit

        $parser->permit(qw(:INLINE !:LINK));

permit adds TAGs and :CLASSes to the list of permitted tags. Use '!' in front of a tag or class to negate the meaning.

forbid

        $parser->forbid(qw(:ALL !:TEXT));

forbid adds TAGs and :CLASSes to the list of forbidden tags. Use '!' in front of a tag or class to negate the meaning.

isPermitted

        if($parser->isPermitted('IMG')) {
                # Yay, [IMG] tags
        } else {
                # Damn, no [IMG] tags
        }

forbid checks if a tag is permitted by the current settings.

parse

        my $tree = $parser->parse('[b]BBCode[/b] text.');

parse creates a parse tree for the given BBCode. The result is a tree of BBCode::Tag objects. The most common use of the parse tree is to convert it to HTML using BBCode::Tag->toHTML():

        my $html = $tree->toHTML;

SEE ALSO

BBCode::Tag

AUTHOR

Donald King <dlking@cpan.org>