Highlight text-only differences in HTML files
This bug was originally reported by Paul Wise (@pabs) in Debian bug #1022209:
Package: diffoscope
Version: 224
Severity: wishlist
It would be nice if diffoscope could help highlight that HTML files
differ in the text output or if they differ only in the non-text HTML
bytes like the page title, the stylesheet etc.
The proposal would be that by default diffoscope would convert HTML
files to text, diff that and if there were text differences then
display them, with a comment saying these are differences in the text.
In situations where the text does not differ, diffoscope would do a
line diff of the HTML file itself, with a comment saying the text of
the two files was not different.
This is useful in some situations like when comparing old versions of a
document with newer versions of a document or similar. In particular it
would have been useful when preparing this mail to debian-mentors:
https://lists.debian.org/msgid-search/197a4671e7694c24424b91b4d7288867c0c85d9b.camel@debian.org
Since there are many different tools for conversion of HTML to text and
each of them have different bugs and features, probably this feature
should allow the user to choose the tool they want to use for this.
$ head -vn-0 *.html
==> bar.html <==
<html>
<head>
<title>bar</title>
<style>
<!--
BODY {
BACKGROUND: #FFFFFF;
COLOR: #000000;
-->
</style>
</head>
<body>
<p>
bar
</p>
</body>
</html>
==> foo.html <==
<html>
<head>
<title>foo</title>
<style>
<!--
BODY {
BACKGROUND: #000000;
COLOR: #FFFFFF;
-->
</style>
</head>
<body>
<p>
foo
</p>
</body>
</html>
$ diffoscope foo.html bar.html
--- foo.html
+++ bar.html
@@ -1,17 +1,17 @@
<html>
<head>
-<title>foo</title>
+<title>bar</title>
<style>
<!--
BODY {
-BACKGROUND: #000000;
-COLOR: #FFFFFF;
+BACKGROUND: #FFFFFF;
+COLOR: #000000;
-->
</style>
</head>
<body>
<p>
-foo
+bar
</p>
</body>
</html>
$ diff -u <(w3m -dump foo.html) <(w3m -dump bar.html)
--- /dev/fd/63 2022-10-22 08:52:33.581676470 +0800
+++ /dev/fd/62 2022-10-22 08:52:33.585676477 +0800
@@ -1,2 +1,2 @@
-foo
+bar
$ diff -u <(html2text foo.html) <(html2text bar.html)
--- /dev/fd/63 2022-10-22 08:54:43.793859066 +0800
+++ /dev/fd/62 2022-10-22 08:54:43.781859049 +0800
@@ -1 +1 @@
-foo
+bar