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. OVERVIEW A `BBCode::Parser' object stores various settings that affect the parsing process. Simple settings are typically set when the parser is created using new(), but they can be queried using get() and altered using set(). See "SETTINGS" for more information. In addition to the simple settings, specific BBCode tags (or classes of tags) can be permitted or forbidden, using permit() and forbid() respectively. By default, the only forbidden tag is `[HTML]', which is normally a security violation if permitted. See "CLASSES" for a list of tag classes. Once the parser has been configured appropriately, parse trees can be created using the parse() method. The parse tree will consist of objects derived from BBCode::Tag; the root of the tree will be a BBCode::Body object. Converting the parse tree to HTML is quite simple: call toHTML() on the root of the tree. Likewise, the parse tree can be converted back to BBCode by calling toBBCode(). See "METHODS" in BBCode::Tag to find out what other output methods are available. SETTINGS The following settings can be manipulated using get() and set(). css_prefix (Type: String; Default: "bbcode-") Many BBCode tags will add CSS classes as style hooks in the output HTML, such as `
'. They represent blocks of content that stand alone from other blocks, often with vertical padding to separate them visually. In general, `BLOCK' tags are not allowed inside `INLINE' tags. INLINE Tags with the `INLINE' class are those that translate into inline elements in HTML, e.g. `[URL]', which becomes `'. They represent content that's still part of the current flow of text, not the start of a new block. LINK Tags with the `LINK' class are hyperlinks to external resources. At the moment, the two tags with the `LINK' class are `[URL]' and `[EMAIL]'. TEXT Tags with the `TEXT' class are plain text. At the moment, the three tags with the `TEXT' class are `[TEXT]', `[ENT]', and `[BR]'. METHODS DEFAULT my $tree = BBCode::Parser->DEFAULT->parse($code); `DEFAULT' returns the default parser. If you change the default parser, all future parsers created with new() will incorporate your changes. However, all existing parsers will be unaffected. clone my $parser = BBCode::Parser->new(follow_links => 1); my $clone = $parser->clone; $clone->forbid('IMG'); printf "[IMG] is%s OK\n", ($parser->isPermitted('IMG') ? "" : " not"); # Prints "[IMG] is OK", since forbid('IMG') applies only to the clone. `clone' creates a new parser that copies the settings of an existing parser. After cloning, the two parsers are completely independent; changing settings in one does not affect the other. If any arguments are given, they are handed off to the set() method. 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('follow_override')) { # [URL FOLLOW] permitted } else { # [URL FOLLOW] forbidden } `get' fetches the current settings for the given parser. See "SETTINGS" for a list of available settings. set $parser->set(follow_override => 1); `set' alters the settings for the given parser. See "SETTINGS" for a list of available settings. addTag TODO: Implement and document 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 { # Darn, no [IMG] tags } `isPermitted' 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 svn://chronos-tachyon.net/projects/BBCode-Parser AUTHOR Donald King