line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################### |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This file copyright (c) 2009 by Randy J. Ray, all rights reserved |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copying and distribution are permitted under the terms of the Artistic |
6
|
|
|
|
|
|
|
# License 2.0 (http://www.opensource.org/licenses/artistic-license-2.0.php) or |
7
|
|
|
|
|
|
|
# the GNU LGPL (http://www.opensource.org/licenses/lgpl-2.1.php). |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
############################################################################### |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Description: A sub-class of Text::Textile::Plaintext that plugs in a |
12
|
|
|
|
|
|
|
# RTF formatter in place of the plain-text one. |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Functions: new |
15
|
|
|
|
|
|
|
# textile |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# Libraries: HTML::FormatRTF |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# Global Consts: $VERSION |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
############################################################################### |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package Text::Textile::RTF; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
1430
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
26
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
27
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
28
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
29
|
1
|
|
|
1
|
|
6
|
use subs qw(new textile); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
30
|
1
|
|
|
1
|
|
51
|
use base qw(Exporter Text::Textile::Plaintext); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
124
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Scalar::Util qw(blessed reftype); |
33
|
|
|
|
|
|
|
require HTML::FormatRTF; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$VERSION = '0.101'; |
36
|
|
|
|
|
|
|
$VERSION = eval $VERSION; ## no critic |
37
|
|
|
|
|
|
|
@EXPORT = (); |
38
|
|
|
|
|
|
|
@EXPORT_OK = qw(textile); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
############################################################################### |
41
|
|
|
|
|
|
|
# |
42
|
|
|
|
|
|
|
# Sub Name: new |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# Description: Look for "formatter" arguments, and/or create a RTF-based |
45
|
|
|
|
|
|
|
# formatter before relegating to the parent-class |
46
|
|
|
|
|
|
|
# constructor. |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# Arguments: NAME IN/OUT TYPE DESCRIPTION |
49
|
|
|
|
|
|
|
# $class in scalar Class we are blessing into |
50
|
|
|
|
|
|
|
# %args in hash Additional arguments |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# Returns: object reference, dies if given bad "formatter" data |
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
############################################################################### |
55
|
|
|
|
|
|
|
sub new |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
my ($class, %args) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ($args{formatter}) |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
if (!blessed $args{formatter}) |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
die __PACKAGE__ . "::new: Argument to 'formatter' must be an " . |
64
|
|
|
|
|
|
|
'object or a hash reference, stopped' |
65
|
|
|
|
|
|
|
unless (reftype($args{formatter}) eq 'HASH'); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$args{formatter} = HTML::FormatRTF->new(%{$args{formatter}}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
$args{formatter} = HTML::FormatPS->new(); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$class->SUPER::new(%args); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
############################################################################### |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# Sub Name: textile |
81
|
|
|
|
|
|
|
# |
82
|
|
|
|
|
|
|
# Description: A wrapper around the parent-class version, so that this |
83
|
|
|
|
|
|
|
# can be properly exported. |
84
|
|
|
|
|
|
|
# |
85
|
|
|
|
|
|
|
# Arguments: NAME IN/OUT TYPE DESCRIPTION |
86
|
|
|
|
|
|
|
# $self in ref If present, an object of this |
87
|
|
|
|
|
|
|
# class. If not present, a |
88
|
|
|
|
|
|
|
# throw-away one is created. |
89
|
|
|
|
|
|
|
# $content in scalar Content to be converted to |
90
|
|
|
|
|
|
|
# plain text. |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
# Returns: return value from SUPER::textile |
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
############################################################################### |
95
|
|
|
|
|
|
|
sub textile |
96
|
|
|
|
|
|
|
{ |
97
|
|
|
|
|
|
|
my ($self, $content) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
unless (blessed $self && $self->isa('Text::Textile::RTF')) |
100
|
|
|
|
|
|
|
{ |
101
|
|
|
|
|
|
|
$content = $self; |
102
|
|
|
|
|
|
|
$self = __PACKAGE__->new(); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$self->SUPER::textile($content); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Text::Textile::RTF - Generate RTF output from Textile mark-up |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SYNOPSIS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
use Text::Textile::RTF qw(textile); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $textile = <
|
119
|
|
|
|
|
|
|
h1. Heading |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
A _simple_ demonstration of Textile markup. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
* One |
124
|
|
|
|
|
|
|
* Two |
125
|
|
|
|
|
|
|
* Three |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
"More information":http://www.textism.com/tools/textile is available. |
128
|
|
|
|
|
|
|
EOT |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Procedural interface: |
131
|
|
|
|
|
|
|
my $text = textile($textile); |
132
|
|
|
|
|
|
|
print $text; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# Object-oriented interface |
135
|
|
|
|
|
|
|
my $ttrtf = Text::Textile::RTF->new(); |
136
|
|
|
|
|
|
|
$rtf = $ttrtf->process($textile); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 DESCRIPTION |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
B is a sub-class of B that |
141
|
|
|
|
|
|
|
produces RTF output instead of plain text. See L |
142
|
|
|
|
|
|
|
for more detail. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 METHODS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This class only defines the following two methods. It inherits everything else |
147
|
|
|
|
|
|
|
from B. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item new([%args]) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Create a new instance of this class. This constructor calls the super-class |
154
|
|
|
|
|
|
|
constructor after handling the C parameter and setting up an |
155
|
|
|
|
|
|
|
instance of B to pass to the parent. This method only handles |
156
|
|
|
|
|
|
|
the following parameter: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 8 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item formatter($obj|$hashref) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Specify either a pre-created instance of B (or a suitable |
163
|
|
|
|
|
|
|
sub-class) or a hash-reference of parameters to pass to the constructor when |
164
|
|
|
|
|
|
|
creating one. If this parameter is not present, an object is created with the |
165
|
|
|
|
|
|
|
default parameters (as according to L). |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=back |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
See documentation of the new() method in L for |
170
|
|
|
|
|
|
|
additional recognized parameters. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item textile($textile) |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This method is defined in this class so that it can be imported and used |
175
|
|
|
|
|
|
|
procedurally, as textile() is used in either B or |
176
|
|
|
|
|
|
|
B itself. It renders the Textile mark-up in C<$textile> to HTML, |
177
|
|
|
|
|
|
|
then renders the resulting HTML tree into RTF. It returns the RTF content as a |
178
|
|
|
|
|
|
|
single string. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=back |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 BUGS |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Please report any bugs or feature requests to C
|
185
|
|
|
|
|
|
|
rt.cpan.org>, or through the web interface at |
186
|
|
|
|
|
|
|
L. I |
187
|
|
|
|
|
|
|
will be notified, and then you'll automatically be notified of progress on your |
188
|
|
|
|
|
|
|
bug as I make changes. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SUPPORT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=over 4 |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
L |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
L |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * CPAN Ratings |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * Search CPAN |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * Source code on GitHub |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=back |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This file and the code within are copyright (c) 2009 by Randy J. Ray. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Copying and distribution are permitted under the terms of the Artistic |
221
|
|
|
|
|
|
|
License 2.0 (L) or |
222
|
|
|
|
|
|
|
the GNU LGPL 2.1 (L). |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 SEE ALSO |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
L, L, L, |
227
|
|
|
|
|
|
|
L. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 AUTHOR |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Randy J. Ray C<< >> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |