Text::Diff::HTML(3pm)

πŸ“¦
version 0.08 Β· 2 versions
, in fedora 43

✨ 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" that diff() 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::Diff
  • Algorithm::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 (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