line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::MultiMarkdown::XS; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
113335
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
175
|
|
4
|
5
|
|
|
5
|
|
24
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
720
|
|
5
|
5
|
|
|
5
|
|
35
|
use vars qw(@constants); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
633
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
require DynaLoader; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.001_03"; |
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter DynaLoader); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
BEGIN { |
14
|
5
|
|
|
5
|
|
131
|
our @constants = qw( EXT_COMPATIBILITY |
15
|
|
|
|
|
|
|
EXT_COMPLETE |
16
|
|
|
|
|
|
|
EXT_FILTER_HTML |
17
|
|
|
|
|
|
|
EXT_FILTER_STYLES |
18
|
|
|
|
|
|
|
EXT_NOTES |
19
|
|
|
|
|
|
|
EXT_NO_LABELS |
20
|
|
|
|
|
|
|
EXT_NO_METADATA |
21
|
|
|
|
|
|
|
EXT_OBFUSCATE |
22
|
|
|
|
|
|
|
EXT_PROCESS_HTML |
23
|
|
|
|
|
|
|
EXT_SMART |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
HTML_FORMAT |
26
|
|
|
|
|
|
|
TEXT_FORMAT |
27
|
|
|
|
|
|
|
LATEX_FORMAT |
28
|
|
|
|
|
|
|
MEMOIR_FORMAT |
29
|
|
|
|
|
|
|
BEAMER_FORMAT |
30
|
|
|
|
|
|
|
MAN_FORMAT |
31
|
|
|
|
|
|
|
ODF_FORMAT |
32
|
|
|
|
|
|
|
OPML_FORMAT |
33
|
|
|
|
|
|
|
RTF_FORMAT |
34
|
|
|
|
|
|
|
ORIGINAL_FORMAT |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} |
37
|
5
|
|
|
5
|
|
5131
|
use subs @constants; |
|
5
|
|
|
|
|
131
|
|
|
5
|
|
|
|
|
30
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our @EXPORT = ( 'markdown', '$mmd_version', @constants ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
__PACKAGE__->bootstrap($VERSION); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $format_re = qr{ ^ (?: HTML | TEXT | LATEX | MEMOIR | BEAMER | MAN | ODF | OPML | RTF ) }x; |
44
|
|
|
|
|
|
|
my $false_re = qr{^(?:|0|false|off)$}i; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my %option_defs = ( smart => [ bool => EXT_SMART ], |
47
|
|
|
|
|
|
|
complete => [ bool => EXT_COMPLETE ], |
48
|
|
|
|
|
|
|
obfuscate => [ bool => EXT_OBFUSCATE ], |
49
|
|
|
|
|
|
|
use_metadata => [ invbool => EXT_NO_METADATA ], |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new { |
54
|
7
|
|
|
7
|
0
|
11
|
my $class = shift; |
55
|
7
|
|
|
|
|
8
|
my $options; |
56
|
7
|
50
|
33
|
|
|
24
|
if (@_ == 1 and ref $_[0] eq 'HASH') { |
57
|
0
|
|
|
|
|
0
|
$options = shift; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
7
|
|
|
|
|
12
|
$options = { @_ }; |
61
|
|
|
|
|
|
|
} |
62
|
7
|
|
33
|
|
|
44
|
return bless $options, ref($class) || $class; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub markdown { |
67
|
14
|
|
|
14
|
0
|
59
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Detect functional mode, and create an instance for this run.. |
70
|
14
|
100
|
|
|
|
41
|
unless (ref $self) { |
71
|
7
|
50
|
|
|
|
21
|
if ( $self ne __PACKAGE__ ) { |
72
|
7
|
|
|
|
|
33
|
my $ob = __PACKAGE__->new(); |
73
|
|
|
|
|
|
|
# $self is text, $text is options |
74
|
7
|
|
|
|
|
29
|
return $ob->markdown($self, @_); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
0
|
|
|
|
|
0
|
croak('Calling ' . $self . '->markdown (as a class method) is not supported.'); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
7
|
|
|
|
|
12
|
my ($text, $options) = @_; |
82
|
|
|
|
|
|
|
|
83
|
7
|
|
|
|
|
18
|
my $extensions = EXT_SMART; |
84
|
7
|
|
|
|
|
27
|
my $output_format = HTML_FORMAT; |
85
|
|
|
|
|
|
|
|
86
|
7
|
|
100
|
|
|
22
|
$options ||= {}; |
87
|
|
|
|
|
|
|
|
88
|
7
|
100
|
100
|
|
|
41
|
if (my $value = uc($options->{output} || '')) { |
89
|
3
|
50
|
|
|
|
24
|
if ($value =~ $format_re) { |
90
|
3
|
|
|
|
|
11
|
$output_format = constant("${value}_FORMAT"); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
7
|
|
|
|
|
33
|
foreach my $option (keys %option_defs) { |
95
|
28
|
100
|
|
|
|
74
|
if (exists $options->{$option}) { |
96
|
2
|
|
100
|
|
|
10
|
my $value = $options->{$option} || ''; |
97
|
2
|
|
|
|
|
3
|
my ($type, $flag) = @{$option_defs{$option}}; |
|
2
|
|
|
|
|
6
|
|
98
|
2
|
50
|
|
|
|
7
|
if ($type eq 'bool') { |
|
|
0
|
|
|
|
|
|
99
|
2
|
100
|
|
|
|
20
|
if ($value =~ $false_re) { |
100
|
1
|
|
|
|
|
5
|
$extensions &= ~$flag; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
1
|
|
|
|
|
24
|
$extensions |= $flag; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif ($type eq 'invbool') { |
107
|
0
|
0
|
|
|
|
0
|
if ($value =~ $false_re) { |
108
|
0
|
|
|
|
|
0
|
$extensions |= $flag; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
else { |
111
|
0
|
|
|
|
|
0
|
$extensions &= ~$flag; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
7
|
|
|
|
|
1975
|
return _markdown($text, $extensions, $output_format); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
0
|
|
0
|
sub DESTROY {} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub AUTOLOAD { |
124
|
|
|
|
|
|
|
# This AUTOLOAD is used to 'autoload' constants from the constant() |
125
|
|
|
|
|
|
|
# XS function. |
126
|
|
|
|
|
|
|
|
127
|
38
|
|
|
38
|
|
1164
|
my $constname; |
128
|
38
|
|
|
|
|
45
|
our $AUTOLOAD; |
129
|
38
|
|
|
|
|
255
|
($constname = $AUTOLOAD) =~ s/.*:://; |
130
|
38
|
50
|
|
|
|
114
|
croak "&Text::MultiMarkdown::XS::constant not defined" if $constname eq 'constant'; |
131
|
38
|
|
|
|
|
333
|
my ($error, $val) = constant($constname); |
132
|
38
|
50
|
|
|
|
83
|
if ($error) { croak $error; } |
|
0
|
|
|
|
|
0
|
|
133
|
|
|
|
|
|
|
{ |
134
|
5
|
|
|
5
|
|
4313
|
no strict 'refs'; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
570
|
|
|
38
|
|
|
|
|
46
|
|
135
|
38
|
|
|
50
|
|
234
|
*$AUTOLOAD = sub { $val }; |
|
50
|
|
|
|
|
198
|
|
136
|
|
|
|
|
|
|
} |
137
|
38
|
|
|
|
|
139
|
goto &$AUTOLOAD; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 NAME |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Text::MultiMarkdown::XS |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 SYNOPSIS |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
use Text::MultiMarkdown::XS 'markdown'; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my $html = markdown( $text, { output => 'html' } ); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $latex = markdown( $text, { output => 'latex' } ); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 DESCRIPTION |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
B: this is the first, alpha release of the module and the interface is liable to |
159
|
|
|
|
|
|
|
change without notice. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
C is a wrapper around Fletcher T. Penney's MultiMarkdown library |
162
|
|
|
|
|
|
|
(version 4). |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 OPTIONS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The C function takes a number of options: |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=over 4 |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item C |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
the output format - a case-insensitive string, which may take one of the following values: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 4 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item C |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item C |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=back |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item C |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
boolean value to specify whether a complete document or a fragment should be generated |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item C |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
boolean value to specify whether I quotes should be enabled. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=back |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
The following values are accepted as boolean false values: C, 0, 'false' or 'off' |
194
|
|
|
|
|
|
|
(string values are case-insensitive). Anything else is regarded as true. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 AUTHOR |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Andrew Ford |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
MultiMarkdown library by Fletcher Penney |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
The original Markdown implementation was by John Gruber |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Text::MultiMarkdown::XS Copyright (C) 2013 Andrew Ford |
212
|
|
|
|
|
|
|
All rights reserved. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
MultiMarkdown library Copyright (C) 2010-2013 Fletcher T. Penney with portions copyright |
215
|
|
|
|
|
|
|
by Daniel Jalkut and John MacFarlane. See the file MultiMarkdown-License for details. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
218
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
See L |
221
|
|
|
|
|
|
|
|