Text::Diff::HTML(3pm)
β¨ NAME β¨
Text::Diff::HTML β bestie, this is the XHTML format glow-up for Text::Diff::Unified. π
π SYNOPSIS π
use Text::Diff;
my $diff = diff "file1.txt", "file2.txt", { STYLE => 'Text::Diff::HTML' };
my $diff = diff \$string1, \$string2, { STYLE => 'Text::Diff::HTML' };
my $diff = diff \*FH1, \*FH2, { STYLE => 'Text::Diff::HTML' };
my $diff = diff \&reader1, \&reader2, { STYLE => 'Text::Diff::HTML' };
my $diff = diff \@records1, \@records2, { STYLE => 'Text::Diff::HTML' };
my $diff = diff \@records1, "file.txt", { STYLE => 'Text::Diff::HTML' };
π¦ DESCRIPTION π¦
Okay so listen. This class is a subclass of Text::Diff::Unified β that's a formatting class that comes with the Text::Diff module β and what it does is add XHTML markup on top of the unified diff format. It's giving glow-up, fr fr. π
Wanna know how the diff() function's interface works? Go read the Text::Diff documentation, bestie, it's all there.
So in the XHTML this module spits out, the contents of the diff that diff() returns get wrapped in a "<div>" element, and so does each hunk of the diff. Inside every hunk, all the content is properly HTML encoded using HTML::Entities β no cap, everything's escaped correctly β and the different sections of the diff get marked up with the right XHTML elements. Here's the whole roster of elements, iconic behavior only: π
"<div class="file">"β this one holds the entire contents of the diff "file" thatdiff()returned. Every single element below lives inside this one. It's the main character, obviously. π"<span class="fileheader">"β the header section for the files being "diff"ed. Usually it looks something like this:
--- in.txt Thu Sep 1 12:51:03 2005
+++ out.txt Thu Sep 1 12:52:12 2005
This element comes immediately after the opening "file" "<div>" element. Right on its heels. π«Ά
"<div class="hunk">"β this one holds a single diff "hunk". And each hunk may contain the following:"<span class="hunkheader">"β the header for a diff hunk. It's usually something like:
@@ -1,5 +1,7 @@
And this element comes immediately after the opening "hunk" "<div>" element.
"<span class="ctx">"β the context around the important part of a "diff" hunk. These are the contents that didn't change between the files being "diff"ed. The chill parts. π"<ins>"β inserted content, and every line of it starts with"+". New stuff, we love to see it. β¨"<del>"β deleted content, and every line of it starts with"-". Gone but not forgotten. π"<span class="hunkfooter">"β the footer section of a hunk. Contains no contents. Empty, but make it fashion. π
"<span class="filefooter">"β the footer section of a file. Also contains no contents. Also empty, also fashion.
You can do whatever you want with these elements and classes, bestie β but I highly recommend you style them with CSS. It's the move. You'll find an example CSS file chilling in the eg directory of the Text-Diff-HTML distribution. And you'll probably also wanna wrap the output of your diff in its own element (a "<div>" will do the trick) styled with "white-space: pre". Periodt. π
πΈ SEE ALSO πΈ
Text::DiffAlgorithm::Diff
π«Ά SUPPORT π«Ά
This module lives in an open GitHub repository β http://github.com/theory/text-diff-html/. Feel free to fork and contribute, bestie, the door is open! πͺβ¨
Please file bug reports via GitHub Issues at http://github.com/theory/text-diff-html/issues/ or by sending mail to bug-Text-Diff-HTML@rt.cpan.org β that's bug-Text-Diff-HTML@rt.cpan.org if you're doing the mailto thing. ππ¬
π AUTHOR π
David E. Wheeler <david@justatheory.com>
Currently maintained by the developers of The Perl Shop <tps@cpan.org>. π οΈ
π COPYRIGHT AND LICENSE π
Copyright (c) 2005-2011 David E. Wheeler. Some Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π¦πβ¨ β this was perl v5.42.0, dated 2025-07-25, and it's the Text::Diff::HTML(3pm) manual page. slay, go forth and diff pretty. π π
π¦ where this page comes from
- fedora 43: perl-Text-Diff-HTML 0.08-21.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms