File: dtddiff2html

package info (click to toggle)
dtdparse 2.00-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 352 kB
  • sloc: perl: 6,251; makefile: 4
file content (158 lines) | stat: -rwxr-xr-x 2,869 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/perl
# $Id: dtddiff2html,v 2.2 2005/07/16 03:22:57 ehood Exp $
# Author(s): Earl Hood, <earl@earlhood.com>
# POD at end of file.

use Getopt::Long;
use SGML::DTDParse;

MAIN: {
  my %opts = ();
  GetOptions(\%opts,
    @SGML::DTDParse::CommonOptions
  ) || SGML::DTDParse::usage(-verbose => 0, -exitval => 1);
  SGML::DTDParse::process_common_options(\%opts);

  print <<EOT;
<html>
<head>
<title>Diff</title>
<style type="text/css">
  body {
    background-color: #DDDDDD;
  }
  pre.contextDiff {
    background: #EEEEEE;
    border-color: black;
    border-style: solid;
    border-width: thin;
    padding: 0.25em;
  }
  .diffDel {
    color: red;
  }
  .diffAdd {
    color: green;
  }
  .diffChng {
    color: blue;
  }
</style>
</head>
<body>
<pre class="contextDiff">
EOT

  my $in_chng = 0;
  while (<>) {
    chomp;
    if (/^[!]/) {
      if (/::=/) {
        print '<span class="diffChng">', entify($_), "\n";
        $in_chng = 1;
        next;
      } else {
        print '<span class="diffChng">', entify($_), "</span>\n";
        next;
      }
    }

    if (/^(---|[*+\-])/) {
      if ($in_chng) {
        print "</span>";
        $in_chng = 0;
      }
      elsif ($1 eq '---' || $1 eq '*') {
        print '<b>', entify($_), "</b>\n";
      }
      elsif ($1 eq '+') {
        print '<span class="diffAdd">', entify($_), "</span>\n";
      }
      elsif ($1 eq '-') {
        print '<span class="diffDel">', entify($_), "</span>\n";
      }
      next;
    }

    if ($in_chng && !/\S/) {
      print "</span>";
      $in_chng = 0;
    }

    print entify($_), "\n";
  }

  print qq{</pre>\n};
}

##############################################################################

sub entify {
  my $txt = shift;
  $txt =~ s/&/&amp;/g;
  $txt =~ s/</&lt;/g;
  $txt =~ s/>/&gt;/g;
  $txt;
}

##############################################################################

__END__

=head1 NAME

dtddiff2html - Convert DTD difference to HTML.

=head1 SYNOPSIS

 dtddiff parsed-dtd1.xml parsed-dtd2.xml > dtd-diff.txt
 dtddiff2html dtd-diff.txt > dtd-diff.html

 dtddiff parsed-dtd1.xml parsed-dtd2.xml | dtddiff2html > dtd-diff.html

=head1 DESCRIPTION

B<dtddiff2html> converts the diff-style output of B<dtddiff> into
HTML.  The HTML created basically provides color-highlighting
of the diff output.

=head1 OPTIONS

=over 4

=item --version

Print version and synopsis.

=item --help

Print synopsis and options available.

=item --man

Print manual page.

=back

=head1 SEE ALSO

L<dtddiff|dtddiff>

See L<SGML::DTDParse|SGML::DTDParse> for an overview of the DTDParse package.

=head1 PREREQUISITES

B<Getopt::Long>

=head1 AVAILABILITY

E<lt>I<http://dtdparse.sourceforge.net/>E<gt>

=head1 AUTHORS

Earl Hood, <earl@earlhood.com>

=head1 COPYRIGHT AND LICENSE

See L<SGML::DTDParse|SGML::DTDParse> for copyright and license information.