1package Text::Trac;
2
3use strict;
4use warnings;
5
6use 5.006;
7use Text::Trac::Context;
8use Text::Trac::BlockNode;
9
10our $VERSION = '0.24';
11
12my %Defaults = (
13	html              => '',
14	permalink         => '',
15	min_heading_level => 1,
16	class             => 1,
17	id                => 1,
18	span              => 1,
19);
20
21sub new {
22	my ( $class, %args ) = @_;
23
24	my $self = { %Defaults, %args, };
25
26	bless $self, $class;
27}
28
29sub parse {
30	my $self = shift;
31	my $text = shift or return;
32
33	$self->{trac_url} = '/' unless defined $self->{trac_url};
34	for ( keys %$self ) {
35		if ( $_ =~ /^trac.+url$/ ) {
36			$self->{$_} .= '/' if $self->{$_} !~ m!/$!;
37		}
38	}
39
40	my $c = Text::Trac::Context->new(
41		{
42			%$self, text => $text,
43		}
44	);
45
46	my $node = Text::Trac::BlockNode->new(
47		{
48			context => $c,
49		}
50	);
51	$node->parse;
52
53	$self->{html} = $c->html;
54}
55
56sub html { $_[0]->{html}; }
57
58*process = \&parse;
59
601;
61__END__
62
63=head1 NAME
64
65Text::Trac - Perl extension for formatting text with Trac Wiki Style.
66
67=head1 SYNOPSIS
68
69    use Text::Trac;
70
71    my $parser = Text::Trac->new(
72        trac_url      => 'http://trac.mizzy.org/public/',
73        disable_links => [ qw( changeset ticket ) ],
74    );
75
76    $parser->parse($text);
77
78    print $parser->html;
79
80=head1 DESCRIPTION
81
82Text::Trac parses text with Trac WikiFormatting and convert it to html format.
83
84=head1 METHODS
85
86=head2 new
87
88Constructs Text::Trac object.
89
90Available arguments are:
91
92
93=head3 trac_url
94
95Base URL for TracLinks.Default is /. You can specify each type of URL individually.
96Available URLs are:
97
98=over
99
100=item trac_attachment_url
101
102=item trac_changeset_url
103
104=item trac_log_url
105
106=item trac_milestone_url
107
108=item trac_report_url
109
110=item trac_source_url
111
112=item trac_ticket_url
113
114=item trac_wiki_url
115
116=back
117
118=head3 disable_links
119
120Specify TracLink types you want to disable.
121All types are enabled if you don't specify this option.
122
123    my $parser = Text::Trac->new(
124        disable_links => [ qw( changeset ticket ) ],
125    );
126
127=head3 enable_links
128
129Specify TracLink types you want to enable.Other types are disabled.
130You cannot use both disable_links and enable_links at once.
131
132    my $parser = Text::Trac->new(
133        enable_links => [ qw( changeset ticket ) ],
134    );
135
136
137
138=head2 parse
139
140Parses text and converts it to html format.
141
142=head2 process
143
144An alias of parse method.
145
146=head2 html
147
148Return converted html string.
149
150=head1 SEE ALSO
151
152=over 3
153
154=item  L<Text::Hatena>
155
156=item  L<Trac Guide|https://trac.edgewall.org/wiki/TracGuide>
157
158=item  L<Trac WikiFormatting|https://trac.edgewall.org/wiki/WikiFormatting>
159
160=back
161
162=head1 AUTHORS
163
164Gosuke Miyashita, C<< <gosukenator at gmail.com> >>
165
166Hideaki Tanaka, C<< <drawn.boy at gmail.com)> >>
167
168=head1 BUGS
169
170Please report any bugs or feature requests to
171C<bug-text-trac at rt.cpan.org>, or through the web interface at
172L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-Trac>.
173I will be notified, and then you'll automatically be notified of progress on
174your bug as I make changes.
175
176=head1 SUPPORT
177
178You can find documentation for this module with the perldoc command.
179
180    perldoc Text::Trac
181
182You can also look for information at:
183
184=over 4
185
186=item * AnnoCPAN: Annotated CPAN documentation
187
188L<http://annocpan.org/dist/Text-Trac>
189
190=item * CPAN Ratings
191
192L<http://cpanratings.perl.org/d/Text-Trac>
193
194=item * RT: CPAN's request tracker
195
196L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Trac>
197
198=item * Search CPAN
199
200L<http://search.cpan.org/dist/Text-Trac>
201
202=back
203
204=head1 COPYRIGHT & LICENSE
205
206Copyright 2006 Gosuke Miyashita, all rights reserved.
207
208This program is free software; you can redistribute it and/or modify it
209under the same terms as Perl itself.
210
211=cut
212