| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: Parser.pm 284 2006-12-01 07:51:49Z chronos $ |
|
2
|
|
|
|
|
|
|
package BBCode::Parser; |
|
3
|
6
|
|
|
6
|
|
180767
|
use BBCode::Util qw(:parse :tag); |
|
|
6
|
|
|
|
|
23
|
|
|
|
6
|
|
|
|
|
2226
|
|
|
4
|
6
|
|
|
6
|
|
3753
|
use BBCode::TagSet; |
|
|
6
|
|
|
|
|
20
|
|
|
|
6
|
|
|
|
|
171
|
|
|
5
|
6
|
|
|
6
|
|
4006
|
use BBCode::Tag; |
|
|
6
|
|
|
|
|
21
|
|
|
|
6
|
|
|
|
|
180
|
|
|
6
|
6
|
|
|
6
|
|
3378
|
use BBCode::Body; |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
178
|
|
|
7
|
6
|
|
|
6
|
|
38
|
use Carp qw(croak); |
|
|
6
|
|
|
|
|
14
|
|
|
|
6
|
|
|
|
|
272
|
|
|
8
|
6
|
|
|
6
|
|
29
|
use strict; |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
201
|
|
|
9
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
|
6
|
|
|
|
|
12
|
|
|
|
6
|
|
|
|
|
286
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
BEGIN { |
|
14
|
6
|
|
|
6
|
|
2385
|
die "EBCDIC platforms not supported" unless ord "A" == 0x41; |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
BBCode::Parser - Parses BBCode tags |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
BBCode is a simplified markup language used in several online forums |
|
24
|
|
|
|
|
|
|
and bulletin boards. It originated with phpBB, and remains most popular |
|
25
|
|
|
|
|
|
|
among applications written in PHP. Generally, users author their posts in |
|
26
|
|
|
|
|
|
|
BBCode, and the forum converts it to a permitted subset of well-formed HTML. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
C is a proper recursive parser for BBCode-formatted text. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 OVERVIEW |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
A C object stores various settings that affect the parsing |
|
33
|
|
|
|
|
|
|
process. Simple settings are typically set when the parser is created using |
|
34
|
|
|
|
|
|
|
L, but they can be queried using L and altered |
|
35
|
|
|
|
|
|
|
using L. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
See L"SETTINGS"> for more information. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
In addition to the simple settings, specific BBCode tags (or classes of tags) |
|
40
|
|
|
|
|
|
|
can be permitted or forbidden, using L and |
|
41
|
|
|
|
|
|
|
L respectively. By default, the only forbidden tag is |
|
42
|
|
|
|
|
|
|
C<[HTML]>, which is normally a security violation if permitted. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
See L"CLASSES"> for a list of tag classes. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Once the parser has been configured appropriately, parse trees can be created |
|
47
|
|
|
|
|
|
|
using the L method. The parse tree will consist of objects |
|
48
|
|
|
|
|
|
|
derived from L; the root of the tree will be a |
|
49
|
|
|
|
|
|
|
L object. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Converting the parse tree to HTML is quite simple: call L |
|
52
|
|
|
|
|
|
|
on the root of the tree. Likewise, the parse tree can be converted back to |
|
53
|
|
|
|
|
|
|
BBCode by calling L. See |
|
54
|
|
|
|
|
|
|
L<"METHODS" in BBCode::Tag|BBCode::Tag/"METHODS"> to find out what other |
|
55
|
|
|
|
|
|
|
output methods are available. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SETTINGS |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The following settings can be manipulated using L and L. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item css_prefix |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
(Type: String; Default: "bbcode-") |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Many BBCode tags will add CSS classes as style hooks in the output HTML, such |
|
68
|
|
|
|
|
|
|
as C<< ... >>. This setting allows you to |
|
69
|
|
|
|
|
|
|
override the naming scheme for those hooks. At the moment, more direct control |
|
70
|
|
|
|
|
|
|
of the CSS class names is not available. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item css_direct_styles |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
(Type: Boolean; Default: FALSE) |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Certain style-related BBCode tags, such as [U] (underline) and [S] |
|
77
|
|
|
|
|
|
|
(strike-through) don't have a direct equivalent in modern XHTML 1.0 Strict. |
|
78
|
|
|
|
|
|
|
If this value is TRUE, then the generated HTML will use a C |