line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MarkPerl; |
2
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
3
|
|
|
|
|
|
|
require Exporter; |
4
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
5
|
|
|
|
|
|
|
@EXPORT_OK = qw(parse); |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
119404
|
use Modern::Perl; |
|
2
|
|
|
|
|
16048
|
|
|
2
|
|
|
|
|
16
|
|
8
|
2
|
|
|
2
|
|
2871
|
use Data::Pairs; |
|
2
|
|
|
|
|
4739
|
|
|
2
|
|
|
|
|
82
|
|
9
|
2
|
|
|
2
|
|
1536
|
use English; |
|
2
|
|
|
|
|
6354
|
|
|
2
|
|
|
|
|
11
|
|
10
|
2
|
|
|
2
|
|
3508
|
use Text::Balanced qw(extract_bracketed); |
|
2
|
|
|
|
|
44288
|
|
|
2
|
|
|
|
|
225
|
|
11
|
2
|
|
|
2
|
|
2384
|
use HTML::Entities; |
|
2
|
|
|
|
|
17152
|
|
|
2
|
|
|
|
|
4524
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub heading { |
14
|
0
|
|
|
0
|
0
|
0
|
my $text = shift; |
15
|
0
|
|
|
|
|
0
|
$text =~ /^(\#{1,6})(.+?)(\1)\n/; |
16
|
0
|
|
|
|
|
0
|
my $heading_size = length($1); |
17
|
0
|
|
|
|
|
0
|
print "$2\n"; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub striketext { |
21
|
0
|
|
|
0
|
0
|
0
|
my $text = shift; |
22
|
0
|
|
|
|
|
0
|
$text =~ /^\!\((.+?)\)/; |
23
|
0
|
|
|
|
|
0
|
print "$1"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub strikeword { |
27
|
0
|
|
|
0
|
0
|
0
|
my $text = shift; |
28
|
0
|
|
|
|
|
0
|
$text =~ /^\!(\w+)/; |
29
|
0
|
|
|
|
|
0
|
print "$1"; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub underline { |
33
|
0
|
|
|
0
|
0
|
0
|
my $text = shift; |
34
|
0
|
|
|
|
|
0
|
$text =~ /^_(.+)_/; |
35
|
0
|
|
|
|
|
0
|
print "$1"; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub wordstrong { |
40
|
1
|
|
|
1
|
0
|
3
|
my $text = shift; |
41
|
1
|
|
|
|
|
6
|
$text =~ s/^\$//; |
42
|
1
|
|
|
|
|
13
|
print "$text"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub textstrong { |
46
|
1
|
|
|
1
|
0
|
4
|
my $text = $_[0]; |
47
|
1
|
|
|
|
|
5
|
$text =~ /^\$\{(.+?)\}/; |
48
|
1
|
|
|
|
|
44
|
print "$1"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub wordemp { |
52
|
1
|
|
|
1
|
0
|
4
|
my $text = shift; |
53
|
1
|
|
|
|
|
5
|
$text =~ s/^\@//; |
54
|
1
|
|
|
|
|
23
|
print "$text"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub textemp { |
58
|
1
|
|
|
1
|
0
|
5
|
my $text = shift; |
59
|
1
|
|
|
|
|
5
|
$text =~ /^\@\{(.+?)\}/; |
60
|
1
|
|
|
|
|
27
|
print "$1"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub meta { |
64
|
2
|
|
|
2
|
0
|
7
|
my $text = shift; |
65
|
2
|
|
|
|
|
10
|
$text =~ /^\*\{(.+?)\}\{(.*?)\}\{(.+?)\}/; |
66
|
2
|
|
|
|
|
11
|
my $encoded = encode_entities($3); |
67
|
2
|
|
|
|
|
70
|
print "<$1 $2>$encoded$1>"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub neta { |
71
|
1
|
|
|
1
|
0
|
3
|
my $text = shift; |
72
|
1
|
|
|
|
|
6
|
$text =~ /^\%\{(.+?)\}\{(.+?)\}/; |
73
|
1
|
|
|
|
|
16
|
print "<$1 $2/>"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub print_html_list { |
77
|
0
|
|
|
0
|
0
|
0
|
say " |
78
|
0
|
|
|
|
|
0
|
my $list_ref = shift; |
79
|
0
|
|
|
|
|
0
|
foreach my $element ( @{$list_ref} ) { |
|
0
|
|
|
|
|
0
|
|
80
|
0
|
0
|
|
|
|
0
|
if ( ref $element ) { |
81
|
0
|
|
|
|
|
0
|
say ""; |
82
|
0
|
|
|
|
|
0
|
print_html_list($element); |
83
|
0
|
|
|
|
|
0
|
say ""; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
0
|
|
|
|
|
0
|
say " $element"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
0
|
say ""; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $tokenizers = Data::Pairs->new( |
93
|
|
|
|
|
|
|
[ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
{ meta => qr/^\*\{.+?\}\{.*?\}\{.*?\}/ }, |
96
|
|
|
|
|
|
|
{ meta => \&meta }, |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
{ neta => qr/^\%\{.+?\}\{.+?\}/ }, |
99
|
|
|
|
|
|
|
{ neta => \&neta }, |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
{ heading => qr/^(\#{1,6}).+?(\1)\n/ }, |
102
|
|
|
|
|
|
|
{ heading => \&heading }, |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
{ strikeword => qr/^\!\w+/ }, |
105
|
|
|
|
|
|
|
{ strikeword => \&strikeword }, |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
{ striketext => qr/^\!\(.+\)/ }, |
108
|
|
|
|
|
|
|
{ striketext => \&striketext }, |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
{ underline => qr/^_.+_/ }, |
111
|
|
|
|
|
|
|
{ underline => \&underline }, |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
{ wordstrong => qr/^\$\w+/ }, |
114
|
|
|
|
|
|
|
{ wordstrong => \&wordstrong }, |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
{ textstrong => qr/^\$\{.+?\}/ }, |
117
|
|
|
|
|
|
|
{ textstrong => \&textstrong }, |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
{ wordemp => qr/^\@\w+/ }, |
120
|
|
|
|
|
|
|
{ wordemp => \&wordemp }, |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
{ textemp => qr/^\@\{.+?\}/ }, |
123
|
|
|
|
|
|
|
{ textemp => \&textemp }, |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
{ word => qr/^\w+/ }, |
126
|
|
|
|
|
|
|
{ word => sub { print @_ } |
127
|
|
|
|
|
|
|
}, |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
{ space => qr/^[ ]/ }, |
130
|
|
|
|
|
|
|
{ space => sub { print @_ } |
131
|
|
|
|
|
|
|
}, |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
{ cr => qr/^[\n]/ }, |
134
|
|
|
|
|
|
|
{ cr => sub { say " " } |
135
|
|
|
|
|
|
|
}, |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
{ regular => qr/^./ }, |
138
|
|
|
|
|
|
|
{ regular => sub { print encode_entities("@_") } |
139
|
|
|
|
|
|
|
}, |
140
|
|
|
|
|
|
|
] |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub parse { |
144
|
|
|
|
|
|
|
|
145
|
7
|
|
|
7
|
0
|
13362
|
my $file = shift; |
146
|
7
|
|
|
|
|
12
|
my $out = ""; |
147
|
|
|
|
|
|
|
|
148
|
7
|
|
|
|
|
24
|
TOP: while ($file) { |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
#{ should be on an empty line |
151
|
58
|
100
|
|
|
|
137
|
if ( $file =~ /^q\{/ ) { |
152
|
1
|
|
|
|
|
3
|
my $substr = substr $file, 1; |
153
|
1
|
|
|
|
|
6
|
$substr = extract_bracketed( $substr, "{}" ); |
154
|
1
|
50
|
|
|
|
174
|
if ( defined($substr) ) { |
155
|
1
|
|
|
|
|
31
|
say ""; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
#removes { and newline |
158
|
1
|
|
|
|
|
3
|
my $substr_sub = substr $substr, 2, -2; |
159
|
1
|
|
|
|
|
5
|
my $substr_sub_encoded = encode_entities($substr_sub); |
160
|
1
|
|
|
|
|
28
|
print $substr_sub_encoded; |
161
|
|
|
|
|
|
|
|
162
|
1
|
|
|
|
|
8
|
say "\n"; |
163
|
1
|
|
|
|
|
19
|
$file =~ s/^q$substr//; |
164
|
1
|
|
|
|
|
45
|
next TOP; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
else { |
167
|
0
|
|
|
|
|
0
|
die "Incorrect blockquote"; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#{ should be on an empty line |
172
|
57
|
100
|
|
|
|
105
|
if ( $file =~ /^\{/ ) { |
173
|
1
|
|
|
|
|
8
|
my $substr = extract_bracketed( $file, "{}" ); |
174
|
1
|
50
|
|
|
|
463
|
if ( defined($substr) ) { |
175
|
1
|
|
|
|
|
70
|
say "";
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
#removes { and newline |
178
|
1
|
|
|
|
|
4
|
my $substr_sub = substr $substr, 2, -2; |
179
|
1
|
|
|
|
|
6
|
my $substr_sub_encoded = encode_entities($substr_sub); |
180
|
1
|
|
|
|
|
46
|
print $substr_sub_encoded; |
181
|
|
|
|
|
|
|
|
182
|
1
|
|
|
|
|
11
|
say "\n"; |
183
|
1
|
|
|
|
|
21
|
$file =~ s/^$substr//; |
184
|
1
|
|
|
|
|
5
|
next TOP; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
else { |
187
|
0
|
|
|
|
|
0
|
die "Incorrect code"; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
#html list == perl list |
192
|
56
|
50
|
|
|
|
122
|
if ( $file =~ /^\[/ ) { |
193
|
0
|
|
|
|
|
0
|
my $substr = extract_bracketed( $file, "[]" ); |
194
|
0
|
0
|
|
|
|
0
|
if ( defined($substr) ) { |
195
|
0
|
|
|
|
|
0
|
my $list_ref = eval "$substr"; |
196
|
0
|
|
|
|
|
0
|
print_html_list $list_ref; |
197
|
0
|
|
|
|
|
0
|
$file =~ s/^$substr//; |
198
|
0
|
|
|
|
|
0
|
next TOP; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
else { |
201
|
0
|
|
|
|
|
0
|
die "Incorrect list"; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
56
|
|
|
|
|
179
|
MID: foreach my $key ( $tokenizers->get_keys() ) { |
206
|
1208
|
|
|
|
|
5602
|
my ( $rx, $sub ) = $tokenizers->get_values($key); |
207
|
|
|
|
|
|
|
|
208
|
1208
|
100
|
|
|
|
118087
|
if ( $file =~ $rx ) { |
209
|
56
|
|
|
|
|
134
|
$sub->($MATCH); |
210
|
56
|
|
|
|
|
296
|
$file = $POSTMATCH; |
211
|
56
|
|
|
|
|
321
|
next TOP; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
else { |
214
|
1152
|
|
|
|
|
1849
|
next MID; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 NAME |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Text::MarkPerl - A Perly markup language. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 VERSION |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Version 0.01 |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 SYNOPSIS |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
You can use the script markperl.pl to print out |
233
|
|
|
|
|
|
|
html text. Checkout the demo/* for the markup syntax. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 AUTHOR |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
mucker, C<< >> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 BUGS |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
242
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
243
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 SUPPORT |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
perldoc Text::MarkPerl |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
You can also look for information at: |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=over 4 |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
L |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
L |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item * CPAN Ratings |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
L |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item * Search CPAN |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
L |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=back |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Copyright 2011 mucker. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
284
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
285
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=cut |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
1; # End of Text::MarkPerl |