Debian Codegraph @

lib/Text/Markup/Trac.pm

raw
1 package Text::Markup::Trac;
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::Trac 0.10;
9
10 our $VERSION = '0.42';
11
12 sub import {
13 # Replace the regex if passed one.
14 Text::Markup->register( trac => $_[1] ) if $_[1];
15 }
16
17 sub parser {
18 my ($file, $encoding, $opts) = @_;
19 my %params = @{ $opts };
20 my $trac = Text::Trac->new(%params);
21 open_bom my $fh, $file, ":encoding($encoding)";
22 local $/;
23 my $html = $trac->parse(<$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::Trac - Trac wiki syntax parser for Text::Markup
45
46 =head1 Synopsis
47
48 my $html = Text::Markup->new->parse(file => 'README.trac');
49 my $raw = Text::Markup->new->parse(
50 file => 'README.trac',
51 options => [ raw => 1 ],
52 );
53
54 =head1 Description
55
56 This is the L<Trac wiki syntax|https://trac.edgewall.org/wiki/WikiFormatting>
57 parser 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::Trac> for parsing, and then returns the generated HTML as an encoded
60 UTF-8 string with an C<http-equiv="Content-Type"> element identifying the
61 encoding as UTF-8.
62
63 It recognizes files with the following extensions as Trac:
64
65 =over
66
67 =item F<.trac>
68
69 =item F<.trc>
70
71 =back
72
73 To change it the files it recognizes, load this module directly and pass a
74 regular expression matching the desired extension(s), like so:
75
76 use Text::Markup::Trac qr{tr[au]ck?};
77
78 Normally this module returns the output wrapped in a minimal HTML document
79 skeleton. If you would like the raw output without the skeleton, you can pass
80 the C<raw> option to C<parse>.
81
82 In addition, Text::Markup::Mediawiki supports all of the
83 L<Text::Trac options|Text::Trac/new>, including:
84
85 =over
86
87 =item C<trac_url>
88
89 =item C<disable_links>
90
91 =item C<enable_links>
92
93 =back
94
95 =head1 Author
96
97 David E. Wheeler <[email protected]>
98
99 =head1 Copyright and License
100
101 Copyright (c) 2011-2025 David E. Wheeler. Some Rights Reserved.
102
103 This module is free software; you can redistribute it and/or modify it under
104 the same terms as Perl itself.
105
106 =cut