use strict;
use warnings;

open my $f, 'source' or die $!;

print <<EOF;
<!DOCTYPE HTML>
<title>HTML 5 DOM interfaces</title>
<link rel="stylesheet" href="ref.css">
EOF

my $comment = 0;
while (<$f>) {
    s/<!--.*?-->//g;
    $comment = 0 if s/.*-->//;
    $comment = 1 if s/<!--.*//;
    next if $comment;
    if (/<pre class="idl">interface <dfn>/ .. /<\/pre>/) {
        if (/<pre class="idl">interface <dfn>(.*?)<\/dfn>(.*)/) {
            print qq{<pre class="idl" id="idl-$1">interface $1$2\n};
        } else {
            s/<(?!\/pre>)[^>]+>//g;
            print "$_";
        }
    }
}