HTML::Diff(3pm)

πŸ“¦
version 0.600 Β· 2 versions
  • 0.600 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.600 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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_text contained 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 module
  • XML::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 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