Suggestions on how build an HTML Diff tool?

前端 未结 16 1757
灰色年华
灰色年华 2021-02-02 02:00

In this post I asked if there were any tools that compare the structure (not actual content) of 2 HTML pages. I ask because I receive HTML templates from our designers, and freq

16条回答
  •  一整个雨季
    2021-02-02 02:16

    Run both files through the following Perl script, then use diff -iw to do a case-insensitive, whitespace-ignoring diff.

    #! /usr/bin/perl -w
    
    use strict;
    
    undef $/;
    
    my $html = ;
    
    while ($html =~ /\S/) {
      if ($html =~ s/^\s*// or die "malformed HTML";
        print "<$1>\n";
      } else {
        $html =~ s/^([^<]+)//;
        print "(text)\n";
      }
    }
    

提交回复
热议问题