line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoMojo::Formatter::Text; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
14929
|
use base qw/MojoMojo::Formatter/; |
|
26
|
|
|
|
|
74
|
|
|
26
|
|
|
|
|
1927
|
|
4
|
26
|
|
|
26
|
|
10810
|
use URI::Find; |
|
26
|
|
|
|
|
46998
|
|
|
26
|
|
|
|
|
10845
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
MojoMojo::Formatter::Text - format plain text as xhtml |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This formatter will format content between {{txt}} and {{end}} as |
14
|
|
|
|
|
|
|
XHTML) |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
It is based on Angerwhale/Format/PlainText.pm |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=over 4 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=item format_content_order |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Format order can be 1-99. The Text formatter runs on 10 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
1116
|
|
|
1116
|
1
|
4115
|
sub format_content_order { 10 } |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item format_content |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
calls the formatter. Takes a ref to the content as well as the |
33
|
|
|
|
|
|
|
context object. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub format_content { |
38
|
124
|
|
|
124
|
1
|
987
|
my ( $class, $content, $c ) = @_; |
39
|
|
|
|
|
|
|
|
40
|
124
|
|
|
|
|
637
|
my @lines = split /\n/, $$content; |
41
|
124
|
|
|
|
|
312
|
my $txt; |
42
|
124
|
|
|
|
|
342
|
$$content = ""; |
43
|
124
|
|
|
|
|
931
|
my $start_re=$class->gen_re(qr/txt/); |
44
|
124
|
|
|
|
|
656
|
my $end_re=$class->gen_re(qr/end/); |
45
|
124
|
|
|
|
|
465
|
foreach my $line (@lines) { |
46
|
661
|
50
|
|
|
|
1286
|
if ($txt) { |
47
|
0
|
0
|
|
|
|
0
|
if ( $line =~ m/^(.*)$end_re(.*)$/ ) { |
48
|
0
|
|
|
|
|
0
|
$$content .= MojoMojo::Formatter::Text->to_xhtml( $xhtml ); |
49
|
0
|
|
|
|
|
0
|
$txt = ""; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
0
|
else { $txt .= $line . "\n"; } |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
661
|
50
|
|
|
|
2320
|
if ( $line =~ m/^(.*)$start_re(.*)$/ ) { |
55
|
0
|
|
|
|
|
0
|
$$content .= $1; |
56
|
0
|
|
|
|
|
0
|
$txt = " ".$2; # make it true :) |
57
|
|
|
|
|
|
|
} |
58
|
661
|
|
|
|
|
1770
|
else { $$content .= $line . "\n"; } |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item to_xhtml <txt> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
takes some text and renders it as XHTML. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub to_xhtml { |
70
|
2
|
|
|
2
|
1
|
5
|
my ( $class, $text ) = @_; |
71
|
2
|
|
|
|
|
3
|
my $result; |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
8
|
$text =~ s/&/&/g; |
74
|
2
|
|
|
|
|
5
|
$text =~ s/>/>/g; |
75
|
2
|
|
|
|
|
4
|
$text =~ s/</</g; |
76
|
2
|
|
|
|
|
6
|
$text =~ s/'/'/g; |
77
|
2
|
|
|
|
|
4
|
$text =~ s/"/"/g; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# find URIs |
80
|
|
|
|
|
|
|
my $finder = URI::Find->new( |
81
|
|
|
|
|
|
|
sub { |
82
|
2
|
|
|
2
|
|
1382
|
my($uri, $orig_uri) = @_; |
83
|
2
|
|
|
|
|
7
|
return qq|<a href="$uri">$orig_uri</a>|; |
84
|
2
|
|
|
|
|
18
|
}); |
85
|
2
|
|
|
|
|
36
|
$finder->find(\$text); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# fix paragraphs |
88
|
2
|
|
|
|
|
81
|
my @paragraphs = split /\n+/m, $text; |
89
|
2
|
|
|
|
|
5
|
@paragraphs = grep { $_ !~ /^\s*$/ } @paragraphs; |
|
4
|
|
|
|
|
16
|
|
90
|
2
|
|
|
|
|
6
|
$result = join( ' ', map { "<p>$_</p>" } @paragraphs ); |
|
4
|
|
|
|
|
13
|
|
91
|
2
|
|
|
|
|
28
|
return qq{<div class="formatter_txt">\n$result</div>}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SEE ALSO |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L<MojoMojo>,L<Module::Pluggable::Ordered> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHORS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Daniel Brosseau <dab@catapulse.org> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 LICENSE |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This module is licensed under the same terms as Perl itself. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |