BBCode-Parser
view release on metacpan or search on metacpan
lib/BBCode/Tag.pm view on Meta::CPAN
The value for any named parameter can be given as an anonymous array of length
2. The first element is the parameter name, and the second is the value. If
the first element is undefined or the empty string, the default parameter is
set instead.
=back
Example:
$url = BBCode::Tag->new(
$parser,
'URL',
# Sets the default parameter (style 1)
'http://www.example.com/',
# Sets the FOLLOW parameter
[ 'FOLLOW', '1' ],
);
$text = BBCode::Tag->new(
$parser,
'TEXT',
# Sets the default parameter (style 2)
[ undef, 'Example.com' ],
);
$url->pushBody($text);
=head3 parser
$parser = $tag->parser();
Returns the L<BBCode::Parser object|BBCode::Parser> that this tag was
constructed with.
=head3 isPermitted
if($tag->isPermitted('URL')) {
# $tag can contain [URL] tags
} else {
# [URL] tags are forbidden
}
Checks if the given BBCode tag is allowed in the body of this tag.
=head3 forbidTags
$tag->forbidTags(qw(IMG URL));
Mark the given tagZ<>(s) as forbidden, so that this tag (including all its
children, grandchildren, etc.) can never contain any of the forbidden tags.
At the moment, if a tag already contains one of the tags now forbidden, a
warning is raised. In the future, this behavior will likely change.
=head3 body
# Iterate over all this tag's immediate children
my @body = $tag->body();
foreach my $subtag (@body) { ...; }
# Forcibly add a new child, overriding $tag->isPermitted()
my $body = $tag->body();
my $bold = BBCode::Tag->new($tag->parser(), 'B');
push @$body, $bold;
Returns the list of child tags for this tag. In list context, returns
a list; otherwise, returns an array reference.
CAUTION: The reference returned in scalar context is a direct pointer to a
C<BBCode::Tag> internal structure. It is possible to bypass checks on
security and correctness by altering it directly.
=head3 bodyHTML
print HANDLE $tag->bodyHTML();
Recursively converts everything inside this tag into HTML. In array context,
returns the HTML line-by-line (with '\n' already appended); in scalar context,
returns the HTML as one string.
Odds are that you want to use L<toHTML()|/"toHTML"> instead.
=head3 bodyText
print HANDLE $tag->bodyText();
Recursively converts everything inside this tag into plain text. In array
context, returns the plain text line-by-line (with '\n' already appended); in
scalar context, returns the text as one string.
Odds are that you want to use L<toText()|/"toText"> instead.
=head3 pushBody
$tag->pushBody(
'Image: ',
BBCode::Tag->new(
$tag->parser(),
'IMG',
'http://www.example.org/img.png',
)
);
Appends one or more new child tags to this tag's body. Security and
correctness checks are performed. Use C<eval> to catch any exceptions.
If any arguments are strings, they are upgraded to virtual [TEXT] tags.
=head3 toBBCode
Converts this BBCode tree back to BBCode. The resulting "deparsed" BBCode can
reveal discrepancies between what the user means vs. what BBCode::Parser
thinks the user means.
In a web environment, a round-trip using C<toBBCode> is recommended each time
the user previews his/her message. This makes it easier for the user to spot
troublesome code.
=head3 toHTML
Converts this BBCode tree to HTML. This is generally the entire point of
using BBCode.
At the moment, only XHTML 1.0 Strict output is supported. Future versions will
( run in 5.094 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )