Debian Codegraph @

lib/Text/Markup/Creole.pm

raw
1 package Text::Markup::Creole;
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::WikiCreole;
9
10 our $VERSION = '0.41';
11
12 sub import {
13 # Replace the regex if passed one.
14 Text::Markup->register( creole => $_[1] ) if $_[1];
15 }
16
17 sub parser {
18 my ($file, $encoding, $opts) = @_;
19 open_bom my $fh, $file, ":encoding($encoding)";
20 local $/;
21 my $html = creole_parse(<$fh>);
22 return unless $html =~ /\S/;
23 utf8::encode($html);
24 return $html if { @{ $opts } }->{raw};
25 return qq{<html>
26 <head>
27 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
28 </head>
29 <body>
30 $html
31 </body>
32 </html>
33 };
34
35 }
36
37 1;
38 __END__
39
40 =head1 Name
41
42 Text::Markup::Creole - Creole parser for Text::Markup
43
44 =head1 Synopsis
45
46 my $html = Text::Markup->new->parse(file => 'file.creole');
47 my $raw = Text::Markup->new->parse(
48 file => 'file.creole',
49 options => [ raw => 1 ],
50 );
51
52 =head1 Description
53
54 This is the L<Creole|https://www.wikicreole.org/> parser for L<Text::Markup>.
55 It reads in the file (relying on a
56 L<BOM|https://www.unicode.org/unicode/faq/utf_bom.html#BOM>), hands it off to
57 L<Text::WikiCreole> for parsing, and then returns the generated HTML as an
58 encoded UTF-8 string with an C<http-equiv="Content-Type"> element identifying
59 the encoding as UTF-8.
60
61 It recognizes files with the following extensions as Creole:
62
63 =over
64
65 =item F<.creole>
66
67 =back
68
69 To change it the files it recognizes, load this module directly and pass a
70 regular expression matching the desired extension(s), like so:
71
72 use Text::Markup::Creole qr{cre+ole+};
73
74 Normally this module returns the output wrapped in a minimal HTML document
75 skeleton. If you would like the raw output without the skeleton, you can pass
76 the C<raw> option to C<parse>.
77
78 =head1 Author
79
80 Lucas Kanashiro <[email protected]>
81
82 =head1 Copyright and License
83
84 Copyright (c) 2011-2023 Lucas Kanashiro. Some Rights Reserved.
85
86 This module is free software; you can redistribute it and/or modify it under
87 the same terms as Perl itself.
88
89 =cut