1package Text::WordDiff::HTML;
2
3use strict;
4use HTML::Entities qw(encode_entities);
5use vars qw($VERSION @ISA);
6
7$VERSION = '0.02';
8@ISA = qw(Text::WordDiff::Base);
9
10sub file_header {
11    my $header = shift->SUPER::file_header(@_);
12    return '<div class="file">' unless $header;
13    return qq{<div class="file"><span class="fileheader">$header</span>};
14}
15
16sub hunk_header { return '<span class="hunk">' }
17sub hunk_footer { return '</span>' }
18sub file_footer { return '</div>' }
19
20sub same_items {
21    shift;
22    return encode_entities( join('', @_) );
23}
24
25sub delete_items {
26    shift;
27    return '<del>' . encode_entities( join('', @_) ) . '</del>';
28}
29
30sub insert_items {
31    shift;
32    return '<ins>' . encode_entities( join('', @_) ) . '</ins>';
33}
34
351;
36__END__
37
38
39=begin comment
40
41Fake-out Module::Build. Delete if it ever changes to support =head1 headers
42other than all uppercase.
43
44=head1 NAME
45
46Text::WordDiff::HTML - XHTML formatting for Text::WordDiff
47
48=end comment
49
50=head1 Name
51
52Text::WordDiff::HTML - XHTML formatting for Text::WordDiff
53
54=head1 Synopsis
55
56    use Text::WordDiff;
57
58    my $diff = word_diff 'file1.txt', 'file2.txt'; { STYLE => 'HTML' };
59    my $diff = word_diff \$string1,   \$string2,    { STYLE => 'HTML' };
60    my $diff = word_diff \*FH1,       \*FH2,        { STYLE => 'HTML' };
61    my $diff = word_diff \&reader1,   \&reader2,    { STYLE => 'HTML' };
62    my $diff = word_diff \@records1,  \@records2,   { STYLE => 'HTML' };
63
64    # May also mix input types:
65    my $diff = word_diff \@records1,  'file_B.txt', { STYLE => 'HTML' };
66
67=head1 Description
68
69This class subclasses Text::WordDiff::Base to provide a XHTML formatting for
70Text::WordDiff. See L<Term::WordDiff|Term::WordDiff> for usage details. This
71class should never be used directly.
72
73Text::WordDiff::HTML formats word diffs for viewing in a Web browser. The diff
74content is highlighted as follows:
75
76=over
77
78=item * C<< <div class="file"> >>
79
80This element contains the entire contents of the diff "file" returned by
81C<word_diff()>. All of the following elements are subsumed by this one.
82
83=over
84
85=item * C<< <span class="fileheader"> >>
86
87The header section for the files being C<diff>ed, usually something like:
88
89  --- in.txt	Thu Sep  1 12:51:03 2005
90  +++ out.txt	Thu Sep  1 12:52:12 2005
91
92This element immediately follows the opening "file" C<< <div> >> element, but
93will not be present if Text::WordDif cannot deterimine the file names for both
94files being compared.
95
96=item * C<< <span class="hunk"> >>
97
98This element contains a single diff "hunk". Each hunk may contain the
99following elements:
100
101=over
102
103=item * C<< <ins> >>
104
105Inserted content.
106
107=item * C<< <del> >>
108
109Deleted content.
110
111=back
112
113=back
114
115=back
116
117You may do whatever you like with these elements and classes; I highly
118recommend that you style them using CSS. You'll find an example CSS file in
119the F<eg> directory in the Text-WordDiff distribution.
120
121=head1 See Also
122
123=over
124
125=item L<Text::WordDiff|Text::WordDiff>
126
127=item L<Text::WordDiff::ANSIColor|Text::WordDiff::ANSIColor>
128
129=back
130
131=head1 Bugs
132
133Please send bug reports to <bug-text-worddiff@rt.cpan.org>.
134
135=head1 Author
136
137=begin comment
138
139Fake-out Module::Build. Delete if it ever changes to support =head1 headers
140other than all uppercase.
141
142=head1 AUTHOR
143
144=end comment
145
146David Wheeler <david@kineticode.com>
147
148=head1 Copyright and License
149
150Copyright (c) 2005 Kineticode, Inc. All Rights Reserved.
151
152This module is free software; you can redistribute it and/or modify it under the
153same terms as Perl itself.
154
155=cut
156