forked from whatwg/html-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pre-process-index-generator.pl
66 lines (62 loc) · 2.18 KB
/
.pre-process-index-generator.pl
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
#!/usr/bin/perl -w
use strict;
my $seenInsertionPoint = 0;
my $after = '';
my %definitions;
my $inpre = 0;
while (<>) {
$inpre = 1 if /<pre><code class="idl"/os;
if ($inpre && /(partial )?interface <(span|dfn|a href=#[^ >]*)( id="?([^ ">]*)"?)?[^>]*>([^<:]*)?<\/(span|dfn|a)>/os) {
my $partial = $1;
my $id;
my $name;
if ($partial) {
if ($4) {
($id, $name) = ($4, $5);
} else {
if ($5 eq 'HTMLSourceElement') {
($id, $name) = ('the-source-element-when-used-with-the-picture-element:htmlsourceelement', $5);
} elsif ($5 eq 'XMLDocument') {
($id, $name) = ('loading-xml-documents:xmldocument', $5);
} else {
die "don't know how to create partial interface entry for $name in All Interfaces index";
}
}
$definitions{$name} = { } unless defined $definitions{$name};
$definitions{$name}{partial} = [] unless exists $definitions{$name}{partial};
push @{$definitions{$name}{partial}}, $id;
} else {
if ($5 ne 'HTMLBaseFontElement') {
$name = $5;
$definitions{$name} = { } unless defined $definitions{$name};
die "duplicate interface definitions for $name" if exists $definitions{$name}{primary};
}
}
}
$inpre = 0 if /<\/pre>/os;
if (/^INSERT INTERFACES HERE\n?$/os) {
$seenInsertionPoint = 1;
} else {
if ($seenInsertionPoint) {
$after .= $_;
} else {
print $_;
}
}
}
die unless $seenInsertionPoint;
print " <ul class=\"brief\">\n";
for my $name (sort keys %definitions) {
print " <li><code>$name</code>";
if (exists $definitions{$name}{partial}) {
print ", <a href=#$definitions{$name}{partial}[0]>partial";
print " 1" if @{$definitions{$name}{partial}} > 1;
print "</a>";
for (my $i = 1; $i < @{$definitions{$name}{partial}}; $i++) {
print " <a href=#$definitions{$name}{partial}[$i]>$i</a>";
}
}
print "\n";
}
print " </ul>\n";
print $after;