Debian Codegraph @

lib/Text/Markup/Textile.pm

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