| 1 | # $Id: BBCode.pm,v 1.5 2005/05/15 13:51:33 chaos Exp $ | ||||||||||||||||||||||||||||
| 2 | # $Log: BBCode.pm,v $ | ||||||||||||||||||||||||||||
| 3 | # Revision 1.5 2005/05/15 13:51:33 chaos | ||||||||||||||||||||||||||||
| 4 | # fixed a little bug on processing whitespaces | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # Revision 1.4 2005/05/15 13:45:17 chaos | ||||||||||||||||||||||||||||
| 7 | # stripped ending whitespaces in verbatim paragraph | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # Revision 1.3 2005/05/15 06:14:53 chaos | ||||||||||||||||||||||||||||
| 10 | # change version back to numeric | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | # Revision 1.2 2005/05/09 12:15:00 chaos | ||||||||||||||||||||||||||||
| 13 | # modified tag | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # Revision 1.1 2005/05/09 12:13:34 chaos | ||||||||||||||||||||||||||||
| 16 | # Pod::BBCode | ||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||
| 18 | # vim:ts=4 sw=4 | ||||||||||||||||||||||||||||
| 19 | package Pod::BBCode; | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Pod::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use vars qw/ @ISA $VERSION /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | $VERSION = '1.5'; | |||||||||||||||||||||||||||
| 25 | 1 | @ISA = qw/ Pod::Parser /; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub command | ||||||||||||||||||||||||||||
| 28 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
command: called CC=17 SCAR=46.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 9 | my ($self, $command, $paragraph, $line_num) = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 9 | my $expansion; | |||||||||||||||||||||||||||
| 32 | 9 | my $out_fh = $self->output_handle(); | |||||||||||||||||||||||||||
| 33 | 9 | my ($headColor,$itemColor)=($self->{-headcolor},$self->{-itemcolor}); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 9 | for ( $command ) { | |||||||||||||||||||||||||||
| 36 | 9 | ▶ | /pod/ || /cut/ and return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
/pod/ or /cut/
MC/DC50%1/2
/pod/ or /cut/
/pod/
/cut/
Truth table66%2/3
A or B
A= /pod/B= /cut/
| |||||||||||||||||||||||||||||
| 37 | 8 | ▶ | /begin/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | $self->{ignore_section} = 1; | |||||||||||||||||||||||||||
| 39 | 0 | return; | |||||||||||||||||||||||||||
| 40 | }; | ||||||||||||||||||||||||||||
| 41 | 8 | ▶ | /end/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $self->{ignore_section} = 0; | |||||||||||||||||||||||||||
| 43 | 0 | return; | |||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||
| 45 | 8 | ▶ | /head(\d)/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 8 | $expansion = $self->interpolate($paragraph, $line_num); | |||||||||||||||||||||||||||
| 47 | # convert =head[1-4] to [highlight][size=[5-2]][/size][/highlight] | ||||||||||||||||||||||||||||
| 48 | 8 | ▶ | $expansion = "\n" | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 49 | . "[size=" . (6-$1) . "]" | ||||||||||||||||||||||||||||
| 50 | . ($headColor ? "[color=$headColor]" : '') | ||||||||||||||||||||||||||||
| 51 | . $expansion | ||||||||||||||||||||||||||||
| 52 | . ($headColor ? "[/color]" : '') | ||||||||||||||||||||||||||||
| 53 | . "[/size]" | ||||||||||||||||||||||||||||
| 54 | . "\n"; | ||||||||||||||||||||||||||||
| 55 | 8 | last; | |||||||||||||||||||||||||||
| 56 | }; | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | /over/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | push @{$self->{lists}}, undef; | |||||||||||||||||||||||||||
| 59 | # the opening [list] tag's option can be only determined later | ||||||||||||||||||||||||||||
| 60 | # we can do nothing here | ||||||||||||||||||||||||||||
| 61 | 0 | return; | |||||||||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | /back/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | pop @{$self->{lists}}; | |||||||||||||||||||||||||||
| 65 | 0 | $expansion = "[/list]\n"; | |||||||||||||||||||||||||||
| 66 | 0 | last; | |||||||||||||||||||||||||||
| 67 | }; | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | /item/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if(!defined($self->{lists}[-1])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | # this is the first item | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $self->{lists}[-1] = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | ($paragraph =~ /^\d+\.?\s*/) | ||||||||||||||||||||||||||||
| 73 | ? '1' | ||||||||||||||||||||||||||||
| 74 | : ''; # we consider text item name to be the same as asterisk | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if($self->{lists}[-1] eq '1') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | # numeric list | ||||||||||||||||||||||||||||
| 77 | 0 | $expansion = "[list=1]\n"; | |||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||
| 79 | # asterisk list | ||||||||||||||||||||||||||||
| 80 | 0 | $expansion = "[list]\n"; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||
| 83 | # this is the following item | ||||||||||||||||||||||||||||
| 84 | 0 | $expansion = '' | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # strip item names | ||||||||||||||||||||||||||||
| 88 | 0 | $paragraph =~ s/^[*o-]+\s*//; | |||||||||||||||||||||||||||
| 89 | 0 | $paragraph =~ s/^\d+\.?\s*//; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | $expansion .= '[*]' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 92 | . ($itemColor ? "[color=$itemColor]" : '') | ||||||||||||||||||||||||||||
| 93 | . $self->interpolate($paragraph, $line_num) | ||||||||||||||||||||||||||||
| 94 | . ($itemColor ? "[/color]" : '') | ||||||||||||||||||||||||||||
| 95 | . "\n"; | ||||||||||||||||||||||||||||
| 96 | 0 | last; | |||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 8 | print $out_fh $expansion; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub textblock | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
textblock: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 0 | my ($self, $paragraph, $line_num) = @_; | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | return if $self->{ignore_section}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | my $textColor=$self->{-textcolor}; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | my $expansion = $self->interpolate($paragraph, $line_num); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my $out_fh = $self->output_handle(); | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | print $out_fh ($textColor ? "[color=$textColor]" : '') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 114 | . $expansion | ||||||||||||||||||||||||||||
| 115 | . ($textColor ? "[/color]" : '') | ||||||||||||||||||||||||||||
| 116 | . "\n"; | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | sub interior_sequence | ||||||||||||||||||||||||||||
| 120 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
interior_sequence: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 4 | my ($self, $seq_command, $seq_argument) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 4 | my %markup = ( | |||||||||||||||||||||||||||
| 124 | B => [ '[b]', '[/b]' ], # boldface | ||||||||||||||||||||||||||||
| 125 | I => [ '[i]', '[/i]' ], # italic | ||||||||||||||||||||||||||||
| 126 | F => [ '[pre]', '[/pre]' ], # filename | ||||||||||||||||||||||||||||
| 127 | C => [ '[pre]', '[/pre]' ], # code | ||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 4 | return $markup{$seq_command}[0] . $seq_argument . $markup{$seq_command}[1]; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub verbatim | ||||||||||||||||||||||||||||
| 134 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
verbatim: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | 1 | my ($self, $paragraph, $line_num) = @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | ▶ | return if $self->{ignore_section}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | my $out_fh = $self->output_handle(); | |||||||||||||||||||||||||||
| 140 | # strip ending newlines | ||||||||||||||||||||||||||||
| 141 | 1 | $paragraph =~ s/\s*$//; | |||||||||||||||||||||||||||
| 142 | # vBulletin forum doesn't seem to be able to handle text looks like BBCode tag in | ||||||||||||||||||||||||||||
| 143 | # the middle of tag pair, so we need to convert [] to corresponding HTML entities "[" and "]" | ||||||||||||||||||||||||||||
| 144 | 1 | $paragraph =~ s/\[/[/g; | |||||||||||||||||||||||||||
| 145 | 1 | $paragraph =~ s/\]/]/g; | |||||||||||||||||||||||||||
| 146 | # make paragraph looking like this: | ||||||||||||||||||||||||||||
| 147 | # [code] | ||||||||||||||||||||||||||||
| 148 | # ... | ||||||||||||||||||||||||||||
| 149 | # [/code] | ||||||||||||||||||||||||||||
| 150 | 1 | ▶ | $paragraph = "[code]\n$paragraph\n[/code]\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | if length($paragraph)>0; | ||||||||||||||||||||||||||||
| 152 | 1 | print $out_fh $paragraph; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub interpolate | ||||||||||||||||||||||||||||
| 156 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
interpolate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 158 | 8 | local $_ = $self->SUPER::interpolate(@_); | |||||||||||||||||||||||||||
| 159 | 8 | tr/ \t\r\n/ /s; | |||||||||||||||||||||||||||
| 160 | 8 | s/\s+$//; | |||||||||||||||||||||||||||
| 161 | 8 | return $_; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 1 | 1; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head1 NAME | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | Pod::BBCode - converts a POD file to a page using BB code. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | use Pod::BBCode; | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | my $p = new Pod::BBCode(-headcolor=>'red',-itemcolor=>'blue',-textcolor=>'black'); | ||||||||||||||||||||||||||||
| 175 | $p->parse_from_file('in.pod'); | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | This class converts a file in POD syntax to the BBCode syntax, in order to simplify | ||||||||||||||||||||||||||||
| 180 | the posting process on vBulletin forums. See any vBulletin forum's help for a description | ||||||||||||||||||||||||||||
| 181 | of the BBCode syntax. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | Pod::BBCode derives from Pod::Parser and therefore inherits all its methods. | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | This module was modified from Pod::TikiWiki module. Thanks to the original author. | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =head2 Supported formatting | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =over 4 | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =item * | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | Heading directives (C<=head[1234]>) are handled with [size][/size] tag. | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =head1 NAME --> [size=5]NAME[/size] | ||||||||||||||||||||||||||||
| 196 | =head2 Methods --> [size=4]Methods[/size] | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =item * | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | List items are rendered with [list=1][/list] (for ordered lists) or [list][/list] (for unordered lists) tag. | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =over [list] | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =item * | ||||||||||||||||||||||||||||
| 205 | --> [*] | ||||||||||||||||||||||||||||
| 206 | Text Text | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =over [list=1] | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =item 1 | ||||||||||||||||||||||||||||
| 211 | --> [*] | ||||||||||||||||||||||||||||
| 212 | Text Text | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =back [/list] | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =back [/list] | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | Items with a string are rendered into a asterisked list | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | =item Text | ||||||||||||||||||||||||||||
| 221 | --> [*]Text | ||||||||||||||||||||||||||||
| 222 | Definition Definition | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =item * | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | Interior sequences C<B>, C<I>, C<F> and C<C> are honored. Both C<F> and C<C> | ||||||||||||||||||||||||||||
| 227 | are rendered as monospaced text. | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | B<bold> --> [b]bold[/b] | ||||||||||||||||||||||||||||
| 230 | I<italic> --> [i]italic[/i] | ||||||||||||||||||||||||||||
| 231 | F<file> --> [pre]file[/pre] | ||||||||||||||||||||||||||||
| 232 | C<code> --> [pre]code[/pre] | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | =back | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =head1 LIMITATIONS | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | =over | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =item * | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | Only the above four interior sequences are handled. C<S>, C<L>, C<X>, C<E> are | ||||||||||||||||||||||||||||
| 243 | ignored. | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =item * | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | BBCode-like text can't display correctly in non-verbatim environment, so be careful. | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | =item * | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | ... | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =back | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | L<perlpod>, L<Pod::Parser> | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | chaoslawful (chaoslaw@cpan.org) | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | This module is free software. You can redistribute and/or modify it under the | ||||||||||||||||||||||||||||
| 264 | terms of the GNU General Public License. | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | Thanks to the author of Pod::TikiWiki again! | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =cut | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||