Debian Codegraph @

lib/Text/Markup/Multimarkdown.pm

raw
1 package Text::Markup::Multimarkdown;
2
3 use 5.8.1;
4 use strict;
5 use warnings;
6 use Text::Markup;
7 use File::BOM qw(open_bom);
8 use Text::MultiMarkdown ();
9
10 our $VERSION = '0.41';
11
12 sub import {
13 # Replace the regex if passed one.
14 Text::Markup->register( multimarkdown => $_[1] ) if $_[1];
15 }
16
17 sub parser {
18 my ($file, $encoding, $opts) = @_;
19 my %params = @{ $opts };
20 my $md = Text::MultiMarkdown->new(%params);
21 open_bom my $fh, $file, ":encoding($encoding)";
22 local $/;
23 my $html = $md->markdown(<$fh>);
24 return unless $html =~ /\S/;
25 utf8::encode($html);
26 return $html if $params{raw};
27 return qq{<html>
28 <head>
29 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
30 </head>
31 <body>
32 $html
33 </body>
34 </html>
35 };
36
37 }
38
39 1;
40 __END__
41
42 =head1 Name
43
44 Text::Markup::Multimarkdown - MultiMarkdown parser for Text::Markup
45
46 =head1 Synopsis
47
48 my $html = Text::Markup->new->parse(file => 'README.mmd');
49 my $raw = Text::Markup->new->parse(
50 file => 'README.mmd',
51 options => [ raw => 1 ],
52 );
53
54 =head1 Description
55
56 This is the L<MultiMarkdown|https://fletcherpenney.net/multimarkdown/> parser
57 for L<Text::Markup>. It reads in the file (relying on a
58 L<BOM|https://www.unicode.org/unicode/faq/utf_bom.html#BOM>), hands it off to
59 L<Text::MultiMarkdown> for parsing, and then returns the generated HTML as an
60 encoded UTF-8 string with an C<http-equiv="Content-Type"> element identifying
61 the encoding as UTF-8.
62
63 It recognizes files with the following extensions as MultiMarkdown:
64
65 =over
66
67 =item F<.mmd>
68
69 =item F<.mmkd>
70
71 =item F<.mmkdn>
72
73 =item F<.mmdown>
74
75 =item F<.multimarkdown>
76
77 =back
78
79 To change it the files it recognizes, load this module directly and pass a
80 regular expression matching the desired extension(s), like so:
81
82 use Text::Markup::Multimarkdown qr{mmm+};
83
84 Normally this module returns the output wrapped in a minimal HTML document
85 skeleton. If you would like the raw output without the skeleton, you can pass
86 the C<raw> option to the format options argument to C<parse>.
87
88 In addition, Text::Markup::Mediawiki supports all of the
89 L<Text::MultiMarkdown options|Text::MultiMarkdown/OPTIONS>, including:
90
91 =over
92
93 =item C<use_metadata>
94
95 =item C<strip_metadata>
96
97 =item C<empty_element_suffix>
98
99 =item C<img_ids>
100
101 =item C<heading_ids>
102
103 =item C<bibliography_title>
104
105 =item C<tab_width>
106
107 =item C<disable_tables>
108
109 =item C<disable_footnotes>
110
111 =item C<disable_bibliography>
112
113 =item C<disable_definition_lists>
114
115 =back
116
117 =head1 Author
118
119 David E. Wheeler <[email protected]>
120
121 =head1 Copyright and License
122
123 Copyright (c) 2011-2025 David E. Wheeler. Some Rights Reserved.
124
125 This module is free software; you can redistribute it and/or modify it under
126 the same terms as Perl itself.
127
128 =cut