HTML::Diff(3pm)
π HTML::Diff π
okay so bestie, welcome to the HTML::Diff man page (it lives in the 3pm section, user contributed Perl docs, iykyk). this little icon is about comparing two HTML strings and handing you back a whole list of differences. no cap. let's get into it π«Ά
β¨ NAME β¨
HTML::Diff β compare two HTML strings and return a list of differences π
π SYNOPSIS π
use HTML::Diff;
$result = html_word_diff($left_text, $right_text);
literally that's it. two strings in, diff energy out β¨
πΈ DESCRIPTION πΈ
so what this module does is compare two strings of HTML and hand you back a list of chunks that show the diff between the two inputs. and here's the thing β changes in formatting count as changes. we do not play about whitespace here bestie π
HTML::Diff does not strictly parse the HTML. nope. instead it uses regular expressions to make a decent effort at understanding the HTML you gave it. which means β and i need you to hear me on this β there are many valid HTML documents for which it will not produce the correct answer. π but also, there may be some invalid HTML documents for which it gives you exactly the answer you were looking for. your mileage may vary. test it on lots of inputs from your domain before relying on it, fr fr π
π¦ the return value π¦
it returns a reference to a list of triples: [<flag>, <left>, <right>]. each triple represents a check of the input texts. the flag tells you whether it's a deletion, an insertion, a modification, or an unchanged chunk. slay.
every single character of each input text is accounted for by some triple in the output. specifically:
- concatenating all the
<left>members from the return value should produce$left_text - likewise, the
<right>members concatenate together to produce$right_text
so like, nothing gets lost. everything is accounted for. main character accountability energy π
β the flag values β
the <flag> is either 'u', '+', '-', or 'c', indicating:
'u'β the two chunks are the same'+'β the$right_textcontained this chunk and the left chunk didn't'-'β vice versa (the left had it, the right didn't)'c'β the two chunks are simply different
this follows the usage of Algorithm::Diff. iconic behaviour honestly π
π how the diff actually gets computed π
the difference is computed on a word-by-word basis, "breaking" on visible words in the HTML text.
- if a tag only is changed, it will not be returned as an independent chunk β instead it'll be shown as a change to one of the neighboring words
- for balanced tags, such as
<b> </b>, it is intended that a change to the tag will be treated as a change to all words in between
like. the tag change gets absorbed into the vibe of the surrounding words. that's the design. that's the intent. periodt π
π SEE ALSO π
Algorithm::Diffβ provides the diff algorithm used in this moduleXML::Diffβ can generate a diff between two XML files, and also patch an XML file, given a diff
π₯ REPOSITORY π₯
<https://github.com/neilb/html-diff>
go star it bestie, it's giving open source royalty π
π§ AUTHOR π§
whipped up by Ezra elias kilty Cooper, <ezra@ezrakilty.net>. π
patch contributed by Adam <asjo@koldfront.dk>. π«Ά
π COPYRIGHT AND LICENSE π
Copyright 2003-2014 by Ezra elias kilty Cooper, <ezra@ezrakilty.net>
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πͺ
okay that's the whole page bestie!! go diff some HTML and be careful out there, it's regex-based so vibe check your inputs first πβ¨
and that's a wrap on this little HTML::Diff(3pm) moment π β brought to you by perl v5.34.0, dated 2022-06-14. mwah, go slay π
π¦ where this page comes from
- debian bookworm: libhtml-diff-perl 0.600-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhtml-diff-perl 0.600-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-diff-perl 0.600-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-diff-perl 0.600-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhtml-diff-perl 0.600-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms