>> etc.). Note that by default
56
|
|
|
|
|
|
|
Markdown isn't interpreted in HTML block-level elements, unless you add |
57
|
|
|
|
|
|
|
a C attribute to the element. See L for |
58
|
|
|
|
|
|
|
details. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This module implements the MultiMarkdown markdown syntax extensions from: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
http://fletcherpenney.net/multimarkdown/ |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SYNTAX |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
For more information about (original) Markdown's syntax, see: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
http://daringfireball.net/projects/markdown/ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This module implements MultiMarkdown, which is an extension to Markdown.. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The extension is documented at: |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
http://fletcherpenney.net/multimarkdown/ |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
and borrows from php-markdown, which lives at: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
http://michelf.com/projects/php-markdown/extra/ |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This documentation is going to be moved/copied into this module for clearer reading in a future release.. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 OPTIONS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
MultiMarkdown supports a number of options to it's processor which control the behaviour of the output document. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
These options can be supplied to the constructor, on in a hash with the individual calls to the markdown method. |
87
|
|
|
|
|
|
|
See the synopsis for examples of both of the above styles. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The options for the processor are: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item use_metadata |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Controls the metadata options below. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item strip_metadata |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
If true, any metadata in the input document is removed from the output document (note - does not take effect in complete document format). |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item empty element suffix |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This option can be used to generate normal HTML output. By default, it is ' />', which is xHTML, change to '>' for normal HTML. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item img_ids |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Controls if tags generated have an id attribute. Defaults to true. |
108
|
|
|
|
|
|
|
Turn off for compatibility with the original markdown. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item heading_ids |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Controls if tags generated have an id attribute. Defaults to true. |
113
|
|
|
|
|
|
|
Turn off for compatibility with the original markdown. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item bibliography_title |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
The title of the generated bibliography, defaults to 'Bibliography'. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item tab_width |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Controls indent width in the generated markup, defaults to 4 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item disable_tables |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
If true, this disables the MultiMarkdown table handling. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item disable_footnotes |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
If true, this disables the MultiMarkdown footnotes handling. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item disable_bibliography |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
If true, this disables the MultiMarkdown bibliography/citation handling. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item disable_definition_lists |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
If true, this disables the MultiMarkdown definition list handling. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=back |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
A number of possible items of metadata can also be supplied as options. |
142
|
|
|
|
|
|
|
Note that if the use_metadata is true then the metadata in the document will overwrite the settings on command line. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Metadata options supported are: |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item document_format |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item use_wikilinks |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item base_url |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item self_url - The document url is prepended to the "#" anchor of footnotes. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 METADATA |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
MultiMarkdown supports the concept of 'metadata', which allows you to specify a number of formatting options |
161
|
|
|
|
|
|
|
within the document itself. Metadata should be placed in the top few lines of a file, on value per line as colon separated key/value pairs. |
162
|
|
|
|
|
|
|
The metadata should be separated from the document with a blank line. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Most metadata keys are also supported as options to the constructor, or options |
165
|
|
|
|
|
|
|
to the markdown method itself. (Note, as metadata, keys contain space, whereas options the keys are underscore separated.) |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
You can attach arbitrary metadata to a document, which is output in HTML tags if unknown, see t/11document_format.t for more info. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
A list of 'known' metadata keys, and their effects are listed below: |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=over |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item document format |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
If set to 'complete', MultiMarkdown will render an entire xHTML page, otherwise it will render a document fragment |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item css |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Sets a CSS file for the file, if in 'complete' document format. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item title |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Sets the page title, if in 'complete' document format. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item use wikilinks |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
If set to '1' or 'on', causes links that are WikiWords to automatically be processed into links. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item base url |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This is the base URL for referencing wiki pages. In this is not supplied, all wiki links are relative. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 METHODS |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 new |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
A simple constructor, see the SYNTAX and OPTIONS sections for more information. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub new { |
208
|
27
|
|
|
27
|
1
|
19012
|
my ($class, %p) = @_; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# Default metadata to 1 |
211
|
27
|
100
|
|
|
|
194
|
$p{use_metadata} = 1 unless exists $p{use_metadata}; |
212
|
|
|
|
|
|
|
# Squash value to [01] |
213
|
27
|
100
|
|
|
|
135
|
$p{use_metadata} = $p{use_metadata} ? 1 : 0; |
214
|
|
|
|
|
|
|
|
215
|
27
|
|
100
|
|
|
959
|
$p{base_url} ||= ''; # This is the base url to be used for WikiLinks |
216
|
|
|
|
|
|
|
|
217
|
27
|
50
|
33
|
|
|
227
|
$p{tab_width} = 4 unless (defined $p{tab_width} and $p{tab_width} =~ m/^\d+$/); |
218
|
|
|
|
|
|
|
|
219
|
27
|
|
50
|
|
|
199
|
$p{document_format} ||= ''; |
220
|
|
|
|
|
|
|
|
221
|
27
|
|
50
|
|
|
168
|
$p{empty_element_suffix} ||= ' />'; # Change to ">" for HTML output |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
#$p{heading_ids} = defined $p{heading_ids} ? $p{heading_ids} : 1; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# For use with WikiWords and [[Wiki Links]] |
226
|
|
|
|
|
|
|
# NOTE: You can use \WikiWord to prevent a WikiWord from being treated as a link |
227
|
27
|
100
|
|
|
|
103
|
$p{use_wikilinks} = $p{use_wikilinks} ? 1 : 0; |
228
|
|
|
|
|
|
|
|
229
|
27
|
100
|
|
|
|
130
|
$p{heading_ids} = defined $p{heading_ids} ? $p{heading_ids} : 1; |
230
|
27
|
50
|
|
|
|
127
|
$p{img_ids} = defined $p{img_ids} ? $p{img_ids} : 1; |
231
|
|
|
|
|
|
|
|
232
|
27
|
|
50
|
|
|
430
|
$p{bibliography_title} ||= 'Bibliography'; # FIXME - Test and document, can also be in metadata! |
233
|
|
|
|
|
|
|
|
234
|
27
|
|
100
|
|
|
157
|
$p{self_url} ||= ''; # Used in footnotes to prepend anchors |
235
|
|
|
|
|
|
|
|
236
|
27
|
|
|
|
|
88
|
my $self = { params => \%p }; |
237
|
27
|
|
33
|
|
|
200
|
bless $self, ref($class) || $class; |
238
|
27
|
|
|
|
|
102
|
return $self; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 markdown |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
The main function as far as the outside world is concerned. See the SYNOPSIS |
244
|
|
|
|
|
|
|
for details on use. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub markdown { |
249
|
89
|
|
|
89
|
1
|
64351
|
my ( $self, $text, $options ) = @_; |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# Detect functional mode, and create an instance for this run.. |
252
|
89
|
100
|
|
|
|
416
|
unless (ref $self) { |
253
|
2
|
100
|
|
|
|
12
|
if ( $self ne __PACKAGE__ ) { |
254
|
1
|
|
|
|
|
5
|
my $ob = __PACKAGE__->new(); |
255
|
|
|
|
|
|
|
# $self is text, $text is options |
256
|
1
|
|
|
|
|
9
|
return $ob->markdown($self, $text); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
else { |
259
|
1
|
|
|
|
|
23
|
croak('Calling ' . $self . '->markdown (as a class method) is not supported.'); |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
87
|
|
100
|
|
|
473
|
$options ||= {}; |
264
|
|
|
|
|
|
|
|
265
|
87
|
|
|
|
|
146
|
%$self = (%{ $self->{params} }, %$options, params => $self->{params}); |
|
87
|
|
|
|
|
1976
|
|
266
|
|
|
|
|
|
|
|
267
|
87
|
|
|
|
|
452
|
$self->_CleanUpRunData($options); |
268
|
|
|
|
|
|
|
|
269
|
87
|
|
|
|
|
1244
|
return $self->_Markdown($text); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub _CleanUpRunData { |
273
|
87
|
|
|
87
|
|
177
|
my ($self, $options) = @_; |
274
|
|
|
|
|
|
|
# Clear the global hashes. If we don't clear these, you get conflicts |
275
|
|
|
|
|
|
|
# from other articles when generating a page which contains more than |
276
|
|
|
|
|
|
|
# one article (e.g. an index page that shows the N most recent |
277
|
|
|
|
|
|
|
# articles): |
278
|
87
|
|
|
|
|
231
|
$self->{_crossrefs} = {}; |
279
|
87
|
|
|
|
|
223
|
$self->{_footnotes} = {}; |
280
|
87
|
|
|
|
|
170
|
$self->{_references} = {}; |
281
|
87
|
|
|
|
|
191
|
$self->{_used_footnotes} = []; # Why do we need 2 data structures for footnotes? FIXME |
282
|
87
|
|
|
|
|
646
|
$self->{_used_references} = []; # Ditto for references |
283
|
87
|
|
|
|
|
188
|
$self->{_citation_counter} = 0; |
284
|
87
|
|
|
|
|
197
|
$self->{_metadata} = {}; |
285
|
87
|
|
|
|
|
203
|
$self->{_attributes} = {}; # Used for extra attributes on links / images. |
286
|
|
|
|
|
|
|
|
287
|
87
|
|
|
|
|
554
|
$self->SUPER::_CleanUpRunData($options); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub _Markdown { |
291
|
|
|
|
|
|
|
# |
292
|
|
|
|
|
|
|
# Main function. The order in which other subs are called here is |
293
|
|
|
|
|
|
|
# essential. Link and image substitutions need to happen before |
294
|
|
|
|
|
|
|
# _EscapeSpecialChars(), so that any *'s or _'s in the |
295
|
|
|
|
|
|
|
# and tags get encoded. |
296
|
|
|
|
|
|
|
# |
297
|
|
|
|
|
|
|
# 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. |
298
|
87
|
|
|
87
|
|
200
|
my ($self, $text) = @_; |
299
|
|
|
|
|
|
|
|
300
|
87
|
|
|
|
|
441
|
$text = $self->_CleanUpDoc($text); |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
# MMD only. Strip out MetaData |
303
|
87
|
100
|
100
|
|
|
70881
|
$text = $self->_ParseMetaData($text) if ($self->{use_metadata} || $self->{strip_metadata}); |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
# Turn block-level HTML blocks into hash entries |
306
|
87
|
|
|
|
|
894
|
$text = $self->_HashHTMLBlocks($text, {interpret_markdown_on_attribute => 1}); |
307
|
|
|
|
|
|
|
|
308
|
87
|
|
|
|
|
110812
|
$text = $self->_StripLinkDefinitions($text); |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
# MMD only |
311
|
87
|
|
|
|
|
312
|
$text = $self->_StripMarkdownReferences($text); |
312
|
|
|
|
|
|
|
|
313
|
87
|
|
|
|
|
669
|
$text = $self->_RunBlockGamut($text, {wrap_in_p_tags => 1}); |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
# MMD Only |
316
|
87
|
100
|
|
|
|
26194
|
$text = $self->_DoMarkdownCitations($text) unless $self->{disable_bibliography}; |
317
|
87
|
100
|
|
|
|
515
|
$text = $self->_DoFootnotes($text) unless $self->{disable_footnotes}; |
318
|
|
|
|
|
|
|
|
319
|
87
|
|
|
|
|
447
|
$text = $self->_UnescapeSpecialChars($text); |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
# MMD Only |
322
|
|
|
|
|
|
|
# This must follow _UnescapeSpecialChars |
323
|
87
|
|
|
|
|
16644
|
$text = $self->_UnescapeWikiWords($text); |
324
|
87
|
100
|
|
|
|
472
|
$text = $self->_FixFootnoteParagraphs($text) unless $self->{disable_footnotes}; # TODO: remove. Doesn't make any difference to test suite pass/failure |
325
|
87
|
100
|
|
|
|
434
|
$text .= $self->_PrintFootnotes() unless $self->{disable_footnotes}; |
326
|
87
|
100
|
|
|
|
443
|
$text .= $self->_PrintMarkdownBibliography() unless $self->{disable_bibliography}; |
327
|
|
|
|
|
|
|
|
328
|
87
|
|
|
|
|
643
|
$text = $self->_ConvertCopyright($text); |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
# MMD Only |
331
|
87
|
100
|
|
|
|
48922
|
if (lc($self->{document_format}) =~ /^complete\s*$/) { |
332
|
4
|
|
|
|
|
147
|
return $self->_xhtmlMetaData() . "\n" . $text . "\n\n |