1Text::Diff::HTML(3) User Contributed Perl Documentation Text::Diff::HTML(3)
2
3
4
6 Text::Diff::HTML - XHTML format for Text::Diff::Unified
7
9 use Text::Diff;
10
11 my $diff = diff "file1.txt", "file2.txt", { STYLE => 'Text::Diff::HTML' };
12 my $diff = diff \$string1, \$string2, { STYLE => 'Text::Diff::HTML' };
13 my $diff = diff \*FH1, \*FH2, { STYLE => 'Text::Diff::HTML' };
14 my $diff = diff \&reader1, \&reader2, { STYLE => 'Text::Diff::HTML' };
15 my $diff = diff \@records1, \@records2, { STYLE => 'Text::Diff::HTML' };
16 my $diff = diff \@records1, "file.txt", { STYLE => 'Text::Diff::HTML' };
17
19 This class subclasses Text::Diff::Unified, a formatting class provided
20 by the Text::Diff module, to add XHTML markup to the unified diff
21 format. For details on the interface of the diff() function, see the
22 Text::Diff documentation.
23
24 In the XHTML formatted by this module, the contents of the diff
25 returned by diff() are wrapped in a "<div>" element, as is each hunk of
26 the diff. Within each hunk, all content is properly HTML encoded using
27 HTML::Entities, and the various sections of the diff are marked up with
28 the appropriate XHTML elements. The elements used are as follows:
29
30 • "<div class="file">"
31
32 This element contains the entire contents of the diff "file"
33 returned by diff(). All of the following elements are subsumed by
34 this one.
35
36 • "<span class="fileheader">"
37
38 The header section for the files being "diff"ed, usually
39 something like:
40
41 --- in.txt Thu Sep 1 12:51:03 2005
42 +++ out.txt Thu Sep 1 12:52:12 2005
43
44 This element immediately follows the opening "file" "<div>"
45 element.
46
47 • "<div class="hunk">"
48
49 This element contains a single diff "hunk". Each hunk may
50 contain the following elements:
51
52 • "<span class="hunkheader">"
53
54 Header for a diff hunk. The hunk header is usually
55 something like:
56
57 @@ -1,5 +1,7 @@
58
59 This element immediately follows the opening "hunk" "<div>"
60 element.
61
62 • "<span class="ctx">"
63
64 Context around the important part of a "diff" hunk. These
65 are contents that have not changed between the files being
66 "diff"ed.
67
68 • "<ins>"
69
70 Inserted content, each line starting with "+".
71
72 • "<del>"
73
74 Deleted content, each line starting with "-".
75
76 • "<span class="hunkfooter">"
77
78 The footer section of a hunk; contains no contents.
79
80 • "<span class="filefooter">"
81
82 The footer section of a file; contains no contents.
83
84 You may do whatever you like with these elements and classes; I highly
85 recommend that you style them using CSS. You'll find an example CSS
86 file in the eg directory in the Text-Diff-HTML distribution. You will
87 also likely want to wrap the output of your diff in its own element (a
88 "<div>" will do) styled with "white-space: pre".
89
91 Text::Diff
92 Algorithm::Diff
93
95 This module is stored in an open GitHub repository
96 <http://github.com/theory/text-diff-html/>. Feel free to fork and
97 contribute!
98
99 Please file bug reports via GitHub Issues
100 <http://github.com/theory/text-diff-html/issues/> or by sending mail to
101 bug-Text-Diff-HTML@rt.cpan.org <mailto:bug-Text-Diff-HTML@rt.cpan.org>.
102
104 David E. Wheeler <david@justatheory.com>
105
106 Currently maintained by the developers of The Perl Shop <tps@cpan.org>.
107
109 Copyright (c) 2005-2011 David E. Wheeler. Some Rights Reserved.
110
111 This module is free software; you can redistribute it and/or modify it
112 under the same terms as Perl itself.
113
114
115
116perl v5.36.0 2023-01-20 Text::Diff::HTML(3)