>> etc.). Note that by default
|
65
|
|
|
|
|
|
|
Markdown isn't interpreted in HTML block-level elements, unless you add |
|
66
|
|
|
|
|
|
|
a C attribute to the element. See L for |
|
67
|
|
|
|
|
|
|
details. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This module implements the MultiMarkdown markdown syntax extensions from: |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
http://fletcherpenney.net/multimarkdown/ |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNTAX |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
For more information about (original) Markdown's syntax, see: |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
http://daringfireball.net/projects/markdown/ |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This module implements MultiMarkdown, which is an extension to Markdown.. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The extension is documented at: |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
http://fletcherpenney.net/multimarkdown/ |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
and borrows from php-markdown, which lives at: |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
http://michelf.com/projects/php-markdown/extra/ |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This documentation is going to be moved/copied into this module for |
|
90
|
|
|
|
|
|
|
clearer reading in a future release.. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 Options |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
MultiMarkdown supports a number of options to its processor which |
|
95
|
|
|
|
|
|
|
control the behaviour of the output document. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
These options can be supplied to the constructor, on in a hash with |
|
98
|
|
|
|
|
|
|
the individual calls to the markdown method. See the synopsis for |
|
99
|
|
|
|
|
|
|
examples of both of the above styles. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The options for the processor are: |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over 4 |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item bibliography_title |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
The title of the generated bibliography, defaults to 'Bibliography'. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item disable_bibliography |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
If true, this disables the MultiMarkdown bibliography/citation handling. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item disable_definition_lists |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
If true, this disables the MultiMarkdown definition list handling. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item disable_footnotes |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
If true, this disables the MultiMarkdown footnotes handling. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item disable_tables |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
If true, this disables the MultiMarkdown table handling. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item empty_element_suffix |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This option can be used to generate normal HTML output. By default, it |
|
128
|
|
|
|
|
|
|
is C<< /> >>, which is xHTML, change to C<< > >> for normal HTML. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item heading_ids |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Controls if C tags generated have an id attribute. Defaults to true. |
|
133
|
|
|
|
|
|
|
Turn off for compatibility with the original markdown. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item heading_ids_spaces_to_dash |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Controls whether spaces in headings should be rendered as "-" characters |
|
138
|
|
|
|
|
|
|
in the heading ids (for compatibility with GitHub markdown, and others) |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item img_ids |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Controls if C tags generated have an id attribute. Defaults to true. |
|
143
|
|
|
|
|
|
|
Turn off for compatibility with the original markdown. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item strip_metadata |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
If true, any metadata in the input document is removed from the output |
|
148
|
|
|
|
|
|
|
document (note - does not take effect in complete document format). |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item tab_width |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Controls indent width in the generated markup, defaults to 4 |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item transliterated_ids |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
In markdown label values, change accented and other non-ASCII letter |
|
157
|
|
|
|
|
|
|
characters with L. If that module is not available, |
|
158
|
|
|
|
|
|
|
this issues a warning and does nothing. When C is true, |
|
159
|
|
|
|
|
|
|
this is ignored. The default is false. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item unicode_ids |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
In markdown label values, allow any Unicode letter character along |
|
164
|
|
|
|
|
|
|
with the allowed ASCII symbol characters. This overrules |
|
165
|
|
|
|
|
|
|
C when true. The default is false. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item use_metadata |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Controls the metadata options below. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 Metadata |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
MultiMarkdown supports the concept of 'metadata', which allows you to |
|
176
|
|
|
|
|
|
|
specify a number of formatting options within the document itself. |
|
177
|
|
|
|
|
|
|
Metadata should be placed in the top few lines of a file, on value per |
|
178
|
|
|
|
|
|
|
line as colon separated key/value pairs. The metadata should be |
|
179
|
|
|
|
|
|
|
separated from the document with a blank line. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Most metadata keys are also supported as options to the constructor, |
|
182
|
|
|
|
|
|
|
or options to the markdown method itself. (Note, as metadata, keys |
|
183
|
|
|
|
|
|
|
contain space, whereas options the keys are underscore separated.) |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
You can attach arbitrary metadata to a document, which is output in |
|
186
|
|
|
|
|
|
|
HTML C<< >> tags if unknown, see F for |
|
187
|
|
|
|
|
|
|
an example. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
These are the known metadata keys: |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=over 4 |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item document_format |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
If set to 'complete', MultiMarkdown will render an entire xHTML page, |
|
196
|
|
|
|
|
|
|
otherwise it will render a document fragment |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=over 4 |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item base url |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This is the base URL for referencing wiki pages. In this is not |
|
203
|
|
|
|
|
|
|
supplied, all wiki links are relative. |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item css |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Sets a CSS file for the file, if in 'complete' document format. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item title |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Sets the page title, if in 'complete' document format. |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=back |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item use wikilinks |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
If set to '1' or 'on', causes links that are WikiWords to |
|
218
|
|
|
|
|
|
|
automatically be processed into links. |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=back |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head2 Class methods |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=over 4 |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item new |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
A simple constructor, see the SYNTAX and OPTIONS sections for more information. |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
my %defaults; |
|
233
|
|
|
|
|
|
|
BEGIN { |
|
234
|
26
|
|
|
26
|
|
18475
|
%defaults = ( |
|
235
|
|
|
|
|
|
|
use_metadata => 1, |
|
236
|
|
|
|
|
|
|
base_url => '', |
|
237
|
|
|
|
|
|
|
tab_width => 4, |
|
238
|
|
|
|
|
|
|
document_format => '', |
|
239
|
|
|
|
|
|
|
empty_element_suffix => ' />', |
|
240
|
|
|
|
|
|
|
use_wikilinks => 0, |
|
241
|
|
|
|
|
|
|
heading_ids => 1, |
|
242
|
|
|
|
|
|
|
img_ids => 1, |
|
243
|
|
|
|
|
|
|
bibliography_title => 'Bibliography', |
|
244
|
|
|
|
|
|
|
self_url => '', |
|
245
|
|
|
|
|
|
|
heading_ids_spaces_to_dash => '', |
|
246
|
|
|
|
|
|
|
); |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub new { |
|
251
|
120
|
|
|
120
|
1
|
291590
|
my ($class, %args) = @_; |
|
252
|
|
|
|
|
|
|
|
|
253
|
120
|
|
|
|
|
1470
|
my %p = ( %defaults, %args ); |
|
254
|
|
|
|
|
|
|
|
|
255
|
120
|
|
|
|
|
474
|
my @binary = qw(use_metadata use_wikilinks); |
|
256
|
120
|
100
|
|
|
|
757
|
$p{$_} = $p{$_} ? 1 : 0 for @binary; |
|
257
|
|
|
|
|
|
|
|
|
258
|
120
|
50
|
|
|
|
950
|
unless( $p{tab_width} =~ m/^[0-9]+$/ ) { |
|
259
|
0
|
|
|
|
|
0
|
carp "tab_width did not look like a decimal number, so using the default 4"; |
|
260
|
0
|
|
|
|
|
0
|
$p{tab_width} = 4; |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
|
|
263
|
120
|
|
|
|
|
510
|
_process_id_handler( \%args, \%p ); |
|
264
|
|
|
|
|
|
|
|
|
265
|
120
|
|
|
|
|
374
|
my $self = { params => \%p }; |
|
266
|
120
|
|
66
|
|
|
574
|
bless $self, ref($class) || $class; |
|
267
|
120
|
|
|
|
|
612
|
return $self; |
|
268
|
|
|
|
|
|
|
} |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub _id_handler { |
|
271
|
237
|
50
|
|
237
|
|
935
|
defined $_[0]->{id_handler} ? $_[0]->{id_handler} : \&_default_id_handler |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub _default_id_handler { |
|
275
|
227
|
|
|
227
|
|
107553
|
my ($label) = @_; |
|
276
|
|
|
|
|
|
|
|
|
277
|
227
|
|
|
|
|
1099
|
$label =~ s/[^A-Za-z0-9:_.-]//g; |
|
278
|
227
|
|
|
|
|
636
|
$label =~ s/\A[^A-Za-z]+//g; |
|
279
|
227
|
|
|
|
|
541
|
$label =~ s/-+/-/g; |
|
280
|
227
|
|
|
|
|
431
|
$label =~ s/-+\z//g; |
|
281
|
|
|
|
|
|
|
|
|
282
|
227
|
|
|
|
|
673
|
return $label; |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
0
|
|
|
|
|
0
|
BEGIN { |
|
286
|
26
|
|
|
26
|
|
108
|
my $has_unidecode = eval { require Text::Unidecode }; |
|
|
26
|
|
|
|
|
14623
|
|
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub _transliteration_id_handler { |
|
289
|
22
|
|
|
22
|
|
58
|
my ($label) = @_; |
|
290
|
|
|
|
|
|
|
|
|
291
|
22
|
50
|
|
|
|
61
|
unless ($has_unidecode ) { |
|
292
|
0
|
|
|
|
|
0
|
carp "Need Text::Unidecode to for transliterated_ids, but could not load it. Falling back to default id handler"; |
|
293
|
0
|
|
|
|
|
0
|
return _default_id_handler($label); |
|
294
|
|
|
|
|
|
|
} |
|
295
|
|
|
|
|
|
|
|
|
296
|
22
|
|
|
|
|
109
|
$label = Text::Unidecode::unidecode($label); |
|
297
|
|
|
|
|
|
|
|
|
298
|
22
|
|
|
|
|
5296
|
$label =~ s/\s+//g; |
|
299
|
22
|
|
|
|
|
115
|
$label =~ s/\A[^A-Za-z]+//g; |
|
300
|
22
|
|
|
|
|
126
|
$label =~ s/-+/-/g; |
|
301
|
22
|
|
|
|
|
72
|
$label =~ s/-+\z//g; |
|
302
|
|
|
|
|
|
|
|
|
303
|
22
|
|
|
|
|
86
|
return $label; |
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
{ |
|
307
|
26
|
|
|
26
|
|
232
|
no warnings qw(redefine); |
|
|
26
|
|
|
|
|
148
|
|
|
|
26
|
|
|
|
|
15714
|
|
|
|
26
|
|
|
|
|
51331
|
|
|
308
|
26
|
50
|
|
|
|
200153
|
*_transliteration_id_handler = \&_default_id_handler unless $has_unidecode; |
|
309
|
|
|
|
|
|
|
} |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
sub _unicode_id_handler { |
|
312
|
30
|
|
|
30
|
|
82
|
my ($label) = @_; |
|
313
|
|
|
|
|
|
|
|
|
314
|
30
|
|
|
|
|
140
|
$label =~ s/\s+//g; |
|
315
|
30
|
|
|
|
|
220
|
$label =~ s/\W+/-/g; |
|
316
|
30
|
|
|
|
|
101
|
$label =~ s/\A\P{Letter}+//g; |
|
317
|
30
|
|
|
|
|
171
|
$label =~ s/-+/-/g; |
|
318
|
30
|
|
|
|
|
118
|
$label =~ s/-+\z//g; |
|
319
|
30
|
|
|
|
|
115
|
return $label; |
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub _process_id_handler { |
|
323
|
120
|
|
|
120
|
|
272
|
my( $args, $p ) = @_; |
|
324
|
|
|
|
|
|
|
|
|
325
|
120
|
|
|
|
|
439
|
$p->{id_handler} = \&_default_id_handler; |
|
326
|
|
|
|
|
|
|
|
|
327
|
120
|
100
|
66
|
|
|
470
|
if ( exists $args->{unicode_ids} and $args->{unicode_ids} and exists $args->{transliterated_ids} ) { |
|
|
|
|
66
|
|
|
|
|
|
328
|
3
|
|
|
|
|
26
|
warn "ignoring transliterated_ids because unicode_ids is true\n"; |
|
329
|
3
|
|
|
|
|
27
|
delete $args->{transliterated_ids}; |
|
330
|
|
|
|
|
|
|
} |
|
331
|
|
|
|
|
|
|
|
|
332
|
120
|
100
|
|
|
|
528
|
if ( $args->{unicode_ids} ) { |
|
|
|
100
|
|
|
|
|
|
|
333
|
6
|
|
|
|
|
21
|
$p->{id_handler} = \&_unicode_id_handler |
|
334
|
|
|
|
|
|
|
} |
|
335
|
|
|
|
|
|
|
elsif ( $args->{transliterated_ids} ) { |
|
336
|
3
|
50
|
|
|
|
13
|
warn "Need Text::Unidecode to transliterate labels, but could not load it\n" |
|
337
|
|
|
|
|
|
|
unless $has_unidecode; |
|
338
|
3
|
|
|
|
|
12
|
$p->{id_handler} = \&_transliteration_id_handler; |
|
339
|
|
|
|
|
|
|
} |
|
340
|
|
|
|
|
|
|
} |
|
341
|
|
|
|
|
|
|
} |
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
=back |
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head2 Instance methods |
|
346
|
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=over 4 |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=item markdown( MARKDOWN_TEXT [, HASHREF] ) |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
This is the legacy interface to this module, but it does too much and |
|
352
|
|
|
|
|
|
|
is a poor name. For the function form, use C |
|
353
|
|
|
|
|
|
|
instead. At the moment that's just a wrapper for C in the |
|
354
|
|
|
|
|
|
|
functional form. For the object-oriented forms, use C instead. |
|
355
|
|
|
|
|
|
|
That's also just a wrapper for this, but will later change to enforce |
|
356
|
|
|
|
|
|
|
object-orientedness (i.e. exclude the functional form). |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
And now the legacy stuff. |
|
359
|
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
This works as either a class method, instance method, or exportable |
|
361
|
|
|
|
|
|
|
function: |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
my $html = Text::MultiMarkdown->markdown( $text ); |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
my $mm = Text::MultiMarkdown->new; |
|
366
|
|
|
|
|
|
|
my $html = $mm->markdown($text); |
|
367
|
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
use Text::MultiMarkdown qw(markdown); |
|
369
|
|
|
|
|
|
|
my $html = markdown( $text ); |
|
370
|
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
Any of these forms take an optional HASH_REF argument for options. These |
|
372
|
|
|
|
|
|
|
are the options for this module or the parent class L: |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
my $html = Text::MultiMarkdown->markdown( $text, { ... } ); |
|
375
|
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
my $mm = Text::MultiMarkdown->new; |
|
377
|
|
|
|
|
|
|
my $html = $mm->markdown($text, { ... }); |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
use Text::MultiMarkdown qw(markdown); |
|
380
|
|
|
|
|
|
|
my $html = markdown( $text, { ... } ); |
|
381
|
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
To make this work in all these cases, since this was the legacy design, |
|
383
|
|
|
|
|
|
|
various unsavory things have to happen. |
|
384
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
When called as a class method, a new object is constructed. We guess |
|
386
|
|
|
|
|
|
|
that it's a class method by looking at the first argument and seeing |
|
387
|
|
|
|
|
|
|
that it looks like a Perl package name. In prior versions this was |
|
388
|
|
|
|
|
|
|
documented to not work, but there was also a TODO test for it to work. |
|
389
|
|
|
|
|
|
|
So, now it works. This might fail if the entire markdown text is exactly |
|
390
|
|
|
|
|
|
|
a valid Perl package name. |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
If the first argument is a blessed reference, we guess that this is |
|
393
|
|
|
|
|
|
|
an instance method. With the optional HASH_REF argument this constructs |
|
394
|
|
|
|
|
|
|
a new argument with all of the settings of the original object and the |
|
395
|
|
|
|
|
|
|
stuff in HASH_REF. This might fail if you have some weird case where |
|
396
|
|
|
|
|
|
|
you call this as a function but pass as the TEXT argument an object that |
|
397
|
|
|
|
|
|
|
has overloaded stringification . |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
=cut |
|
400
|
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
=begin comment |
|
402
|
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
=end comment |
|
404
|
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
There are these situations: |
|
406
|
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
CLASS->markdown( TEXT ); |
|
408
|
|
|
|
|
|
|
CLASS->markdown( TEXT, HASHREF ); |
|
409
|
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
OBJ->markdown( TEXT ); |
|
411
|
|
|
|
|
|
|
OBJ->markdown( TEXT, HASHREF ); |
|
412
|
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
markdown( TEXT ); |
|
414
|
|
|
|
|
|
|
markdown( TEXT, HASHREF ); |
|
415
|
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
These are really: |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
markdown( CLASS, TEXT ) |
|
419
|
|
|
|
|
|
|
markdown( CLASS, TEXT, HASHREF ) |
|
420
|
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
markdown( OBJ, TEXT ) |
|
422
|
|
|
|
|
|
|
markdown( OBJ, TEXT, HASHREF ) |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
markdown( TEXT ); |
|
425
|
|
|
|
|
|
|
markdown( TEXT, HASHREF ); |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
Which breaks down to these groups: |
|
428
|
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
1) markdown( TEXT ); |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
2.1) markdown( TEXT, HASHREF ); |
|
432
|
|
|
|
|
|
|
2.2) markdown( CLASS, TEXT ) |
|
433
|
|
|
|
|
|
|
2.3) markdown( OBJ, TEXT ) |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
3.1) markdown( CLASS, TEXT, HASHREF ) |
|
436
|
|
|
|
|
|
|
3.2) markdown( OBJ, TEXT, HASHREF ) |
|
437
|
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
In 1), 2.2), and 3.1), we should make a new object and then do our |
|
439
|
|
|
|
|
|
|
thing. |
|
440
|
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
In 3.1), the previous version specifically said that we can't call |
|
442
|
|
|
|
|
|
|
this as a class method. |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
In 3.2), we need to merge the options in the existing object with |
|
445
|
|
|
|
|
|
|
the new options. This was never a documented feature though. |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
Part of the tickyness is that interface for Text::Markdown. We need |
|
448
|
|
|
|
|
|
|
to pass the HASHREF to _CleanUpRunData in the SUPER class |
|
449
|
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=cut |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
sub _looks_like_class { |
|
453
|
282
|
|
|
282
|
|
614
|
local $_ = $_[0]; |
|
454
|
282
|
|
|
|
|
5134
|
m/\A\w+(?:::\w+)+\z/; |
|
455
|
|
|
|
|
|
|
} |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
sub markdown { |
|
458
|
181
|
|
|
181
|
1
|
530885
|
my( $self, $text, $options ) = do { |
|
459
|
181
|
100
|
66
|
|
|
2126
|
if ( @_ == 1 and ! ref $_[0] ) { # Case 1 |
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
|
50
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
460
|
8
|
|
|
|
|
40
|
( __PACKAGE__->new, $_[0], {} ); |
|
461
|
|
|
|
|
|
|
} elsif ( @_ == 2 and ! _looks_like_class($_[0]) and ref $_[1] eq ref {} ) { # Case 2.1 |
|
462
|
28
|
|
|
|
|
66
|
( __PACKAGE__->new( %{ $_[1] } ), $_[0], $_[1] ); |
|
|
28
|
|
|
|
|
193
|
|
|
463
|
|
|
|
|
|
|
} elsif ( @_ == 2 and _looks_like_class($_[0]) and ! ref $_[1] ) { # Case 2.2 |
|
464
|
7
|
|
|
|
|
27
|
( $_[0]->new, $_[1] ); |
|
465
|
|
|
|
|
|
|
} elsif ( @_ == 2 and blessed($_[0]) and ! ref $_[1] ) { # Case 2.3 |
|
466
|
102
|
|
|
|
|
519
|
( $_[0], $_[1], {} ); |
|
467
|
|
|
|
|
|
|
} elsif ( @_ == 3 and _looks_like_class($_[0]) and ! ref $_[1] and ref $_[2] eq ref {} ) { # Case 3.1 |
|
468
|
14
|
|
|
|
|
31
|
( $_[0]->new( %{ $_[2]} ), $_[1], $_[2] ); |
|
|
14
|
|
|
|
|
86
|
|
|
469
|
|
|
|
|
|
|
} elsif ( @_ == 3 and blessed($_[0]) and ! ref $_[1] and ref $_[2] eq ref {} ) { # Case 3.2 |
|
470
|
22
|
|
|
|
|
70
|
my %merged = ( %{ $_[0]->{params} }, %{ $_[2] } ); |
|
|
22
|
|
|
|
|
117
|
|
|
|
22
|
|
|
|
|
157
|
|
|
471
|
22
|
|
|
|
|
121
|
my $new = $_[0]->new( %merged ); |
|
472
|
22
|
|
|
|
|
139
|
( $new, $_[1], $_[2] ); |
|
473
|
|
|
|
|
|
|
} else { |
|
474
|
0
|
|
|
|
|
0
|
carp "Unrecognized arguments for markdown()"; |
|
475
|
0
|
|
|
|
|
0
|
return; |
|
476
|
|
|
|
|
|
|
} |
|
477
|
|
|
|
|
|
|
}; |
|
478
|
|
|
|
|
|
|
|
|
479
|
181
|
100
|
|
|
|
570
|
$options = {} unless defined $options; |
|
480
|
|
|
|
|
|
|
|
|
481
|
181
|
|
|
|
|
348
|
%$self = (%{ $self->{params} }, %$options, params => $self->{params}); |
|
|
181
|
|
|
|
|
2875
|
|
|
482
|
181
|
|
|
|
|
931
|
$self->_CleanUpRunData($options); |
|
483
|
|
|
|
|
|
|
|
|
484
|
181
|
|
|
|
|
2617
|
return $self->_Markdown($text); |
|
485
|
|
|
|
|
|
|
} |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
=item multimarkdown_to_html |
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
For the functional interface, you should use this instead of C |
|
490
|
|
|
|
|
|
|
because it's a better name. At the moment it's the same as calling |
|
491
|
|
|
|
|
|
|
C, but eventually this will diverge from the object-oriented |
|
492
|
|
|
|
|
|
|
form C, which is also a better name. |
|
493
|
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
=cut |
|
495
|
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
sub multimarkdown_to_html { |
|
497
|
18
|
|
|
18
|
1
|
99829
|
markdown(@_); |
|
498
|
|
|
|
|
|
|
} |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
=item to_html |
|
501
|
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
As a class or instance method, you should use this instead of C |
|
503
|
|
|
|
|
|
|
because it's a better name. At the moment it's the same as calling |
|
504
|
|
|
|
|
|
|
C, but eventually this will diverge from the functional |
|
505
|
|
|
|
|
|
|
form C, which is also a better name. |
|
506
|
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
=cut |
|
508
|
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
sub to_html { |
|
510
|
31
|
|
|
31
|
1
|
88451
|
markdown(@_); |
|
511
|
|
|
|
|
|
|
} |
|
512
|
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
sub _CleanUpRunData { |
|
514
|
181
|
|
|
181
|
|
482
|
my ($self, $options) = @_; |
|
515
|
|
|
|
|
|
|
# Clear the global hashes. If we don't clear these, you get conflicts |
|
516
|
|
|
|
|
|
|
# from other articles when generating a page which contains more than |
|
517
|
|
|
|
|
|
|
# one article (e.g. an index page that shows the N most recent |
|
518
|
|
|
|
|
|
|
# articles): |
|
519
|
181
|
|
|
|
|
487
|
$self->{_crossrefs} = {}; |
|
520
|
181
|
|
|
|
|
512
|
$self->{_footnotes} = {}; |
|
521
|
181
|
|
|
|
|
379
|
$self->{_references} = {}; |
|
522
|
181
|
|
|
|
|
407
|
$self->{_used_footnotes} = []; # Why do we need 2 data structures for footnotes? FIXME |
|
523
|
181
|
|
|
|
|
364
|
$self->{_used_references} = []; # Ditto for references |
|
524
|
181
|
|
|
|
|
370
|
$self->{_citation_counter} = 0; |
|
525
|
181
|
|
|
|
|
386
|
$self->{_metadata} = {}; |
|
526
|
181
|
|
|
|
|
348
|
$self->{_attributes} = {}; # Used for extra attributes on links / images. |
|
527
|
|
|
|
|
|
|
|
|
528
|
181
|
|
|
|
|
962
|
$self->SUPER::_CleanUpRunData($options); |
|
529
|
|
|
|
|
|
|
} |
|
530
|
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
sub _Markdown { |
|
532
|
|
|
|
|
|
|
# |
|
533
|
|
|
|
|
|
|
# Main function. The order in which other subs are called here is |
|
534
|
|
|
|
|
|
|
# essential. Link and image substitutions need to happen before |
|
535
|
|
|
|
|
|
|
# _EscapeSpecialChars(), so that any *'s or _'s in the |
|
536
|
|
|
|
|
|
|
# and tags get encoded. |
|
537
|
|
|
|
|
|
|
# |
|
538
|
|
|
|
|
|
|
# Can't think of any good way to make this inherit from the Markdown version as ordering is so important, so I've left it. |
|
539
|
181
|
|
|
181
|
|
459
|
my ($self, $text) = @_; |
|
540
|
|
|
|
|
|
|
|
|
541
|
181
|
|
|
|
|
796
|
$text = $self->_CleanUpDoc($text); |
|
542
|
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
# MMD only. Strip out MetaData |
|
544
|
181
|
100
|
100
|
|
|
16731
|
$text = $self->_ParseMetaData($text) if ($self->{use_metadata} || $self->{strip_metadata}); |
|
545
|
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
# Turn block-level HTML blocks into hash entries |
|
547
|
181
|
|
|
|
|
1102
|
$text = $self->_HashHTMLBlocks($text, {interpret_markdown_on_attribute => 1}); |
|
548
|
|
|
|
|
|
|
|
|
549
|
181
|
|
|
|
|
141406
|
$text = $self->_StripLinkDefinitions($text); |
|
550
|
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
# MMD only |
|
552
|
181
|
|
|
|
|
684
|
$text = $self->_StripMarkdownReferences($text); |
|
553
|
|
|
|
|
|
|
|
|
554
|
181
|
|
|
|
|
1249
|
$text = $self->_RunBlockGamut($text, {wrap_in_p_tags => 1}); |
|
555
|
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
# MMD Only |
|
557
|
181
|
100
|
|
|
|
25205
|
$text = $self->_DoMarkdownCitations($text) unless $self->{disable_bibliography}; |
|
558
|
181
|
100
|
|
|
|
854
|
$text = $self->_DoFootnotes($text) unless $self->{disable_footnotes}; |
|
559
|
|
|
|
|
|
|
|
|
560
|
181
|
|
|
|
|
828
|
$text = $self->_UnescapeSpecialChars($text); |
|
561
|
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
# MMD Only |
|
563
|
|
|
|
|
|
|
# This must follow _UnescapeSpecialChars |
|
564
|
181
|
|
|
|
|
30861
|
$text = $self->_UnescapeWikiWords($text); |
|
565
|
181
|
100
|
|
|
|
956
|
$text = $self->_FixFootnoteParagraphs($text) unless $self->{disable_footnotes}; # TODO: remove. Doesn't make any difference to test suite pass/failure |
|
566
|
181
|
100
|
|
|
|
918
|
$text .= $self->_PrintFootnotes() unless $self->{disable_footnotes}; |
|
567
|
181
|
100
|
|
|
|
929
|
$text .= $self->_PrintMarkdownBibliography() unless $self->{disable_bibliography}; |
|
568
|
|
|
|
|
|
|
|
|
569
|
181
|
|
|
|
|
809
|
$text = $self->_ConvertCopyright($text); |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
# MMD Only |
|
572
|
181
|
100
|
|
|
|
1921
|
if (lc($self->{document_format}) =~ /^complete\s*$/) { |
|
573
|
4
|
|
|
|
|
24
|
return $self->_xhtmlMetaData() . "\n" . $text . "\n\n |