@@ -9,26 +9,42 @@ module.exports = class Toc extends Builder {
9
9
return ;
10
10
}
11
11
12
- const html = buildToc ( this . spec ) ;
12
+ const html = Toc . build ( this . spec ) ;
13
13
const tocContainer = this . spec . doc . createElement ( 'div' ) ;
14
14
tocContainer . innerHTML = '<h2>Table of Contents</h2>' + html ;
15
15
const intro = this . spec . doc . querySelector ( 'emu-intro, emu-clause, emu-annex' ) ;
16
16
intro . parentNode . insertBefore ( tocContainer , intro ) ;
17
+
18
+ const bodyClass = this . spec . doc . body . getAttribute ( 'class' ) || '' ;
19
+ this . spec . doc . body . setAttribute ( 'class' , bodyClass + ' oldtoc' ) ;
17
20
}
18
- } ;
19
21
20
- function buildToc ( spec , level ) {
21
- level = level || spec ;
22
+ static build ( level , expandy ) {
23
+ let html = '<ol class="toc">' ;
24
+
25
+ level . subclauses . forEach ( function ( sub ) {
26
+ html += '<li>' ;
22
27
23
- let html = '<ol class="toc">' ;
28
+ if ( expandy ) {
29
+ if ( sub . subclauses . length > 0 ) {
30
+ html += '<span class="item-toggle">◢</span>' ;
31
+ } else {
32
+ html += '<span class="item-toggle-none"></span>' ;
33
+ }
34
+ }
24
35
25
- level . subclauses . forEach ( function ( sub ) {
26
- html += '<li><a href="#' + sub . id + '"><span class="secnum">' + sub . number + '</span> ' + emd . fragment ( sub . title ) + '</a>' ;
27
- if ( sub . subclauses . length > 0 ) html += buildToc ( spec , sub ) ;
28
- html += '</li>' ;
29
- } ) ;
36
+ html += '<a href="#' + sub . id + '" title="' + sub . title + '"><span class="secnum">' + sub . number + '</span> ' + emd . fragment ( shorten ( sub . title ) ) + '</a>' ;
37
+ if ( sub . subclauses . length > 0 ) html += Toc . build ( sub , expandy ) ;
38
+ html += '</li>' ;
39
+ } ) ;
30
40
31
- html += '</ol>' ;
41
+ html += '</ol>' ;
42
+
43
+ return html ;
44
+ }
45
+ } ;
32
46
33
- return html ;
47
+ function shorten ( title ) {
48
+ return title . replace ( 'Static Semantics:' , 'SS:' )
49
+ . replace ( 'Runtime Semantics:' , 'RS:' ) ;
34
50
}
0 commit comments