@@ -3,14 +3,11 @@ document.addEventListener('DOMContentLoaded', function() {
33 var toc = document . getElementById ( 'toc-list' ) ;
44 if ( ! toc ) return ;
55
6- // Clear existing TOC items (tex4ht generates broken links)
76 while ( toc . firstChild ) toc . removeChild ( toc . firstChild ) ;
87
98 var headings = document . querySelectorAll ( 'h2.chapterHead' ) ;
109 headings . forEach ( function ( h , index ) {
11- // Generate an ID if heading doesn't have one or it's empty
1210 if ( ! h . id || h . id === '' ) {
13- // Create slug from heading text
1411 var slug = h . textContent
1512 . toLowerCase ( )
1613 . replace ( / [ ^ a - z 0 - 9 ] + / g, '-' )
@@ -25,35 +22,62 @@ document.addEventListener('DOMContentLoaded', function() {
2522 li . appendChild ( a ) ;
2623 toc . appendChild ( li ) ;
2724 } ) ;
28- } ) ;
2925
30- // Fix margin notes inside definition lists.
31- // Floated margin notes inside dd elements expand the dd height,
32- // causing large gaps in the left-side text. We reposition them
33- // as absolutely positioned elements relative to the article.
34- // Runs on window load (after layout) so getBoundingClientRect is accurate.
35- window . addEventListener ( 'load' , function ( ) {
36- var article = document . querySelector ( 'article' ) ;
37- if ( ! article ) return ;
26+ // Wrap personnel names in .columns-2 sections into individual spans.
27+ // tex4ht outputs names as raw text in a <p>; CSS grid needs elements.
28+ // Each name matches "Name (year – )" or "Name (year – year)" or "Name (year)".
29+ var cols = document . querySelectorAll ( '.columns-2' ) ;
30+ cols . forEach ( function ( col ) {
31+ var ps = col . querySelectorAll ( 'p' ) ;
32+ ps . forEach ( function ( p ) {
33+ var text = p . textContent . trim ( ) ;
34+ if ( ! text ) return ;
3835
39- article . style . position = 'relative' ;
36+ // Split on the pattern: end of one entry ")" followed by start of next
37+ var names = text . match ( / [ ^ ) ] + \) / g) ;
38+ if ( ! names || names . length === 0 ) return ;
4039
41- var ddNotes = document . querySelectorAll ( 'dd .marginnote, dd .sidenote' ) ;
42- var articleRect = article . getBoundingClientRect ( ) ;
40+ // Replace the <p> contents with wrapped spans
41+ while ( p . firstChild ) p . removeChild ( p . firstChild ) ;
42+ names . forEach ( function ( name ) {
43+ var span = document . createElement ( 'span' ) ;
44+ span . className = 'personnel-item' ;
45+ span . textContent = name . trim ( ) ;
46+ p . appendChild ( span ) ;
47+ } ) ;
48+ } ) ;
4349
44- ddNotes . forEach ( function ( note ) {
45- var parent = note . parentElement ;
46- var anchorRect = parent . getBoundingClientRect ( ) ;
47- var topOffset = anchorRect . top - articleRect . top ;
50+ // Move children out of <p> into the columns-2 div directly for grid layout
51+ var items = col . querySelectorAll ( '.personnel-item' ) ;
52+ items . forEach ( function ( item ) {
53+ col . appendChild ( item ) ;
54+ } ) ;
55+ // Remove now-empty <p> elements
56+ var emptyPs = col . querySelectorAll ( 'p' ) ;
57+ emptyPs . forEach ( function ( p ) {
58+ if ( p . textContent . trim ( ) === '' ) p . remove ( ) ;
59+ } ) ;
60+ } ) ;
61+ } ) ;
4862
49- note . style . position = 'absolute' ;
50- note . style . top = topOffset + 'px' ;
51- note . style . right = '0' ;
52- note . style . width = '25%' ;
53- note . style . marginRight = '0' ;
54- note . style . float = 'none' ;
55- note . style . clear = 'none' ;
63+ // Prevent overlapping margin notes inside definition lists.
64+ // CSS positions dd margin notes with position:absolute (removing them
65+ // from flow so dd doesn't expand). But adjacent notes can overlap.
66+ // This script nudges overlapping notes down with a small gap.
67+ window . addEventListener ( 'load' , function ( ) {
68+ var dls = document . querySelectorAll ( 'article > dl' ) ;
69+ dls . forEach ( function ( dl ) {
70+ var notes = dl . querySelectorAll ( 'dd .marginnote, dd .sidenote' ) ;
71+ if ( notes . length < 2 ) return ;
5672
57- article . appendChild ( note ) ;
73+ for ( var i = 1 ; i < notes . length ; i ++ ) {
74+ var prev = notes [ i - 1 ] . getBoundingClientRect ( ) ;
75+ var curr = notes [ i ] . getBoundingClientRect ( ) ;
76+ var overlap = prev . bottom - curr . top ;
77+ if ( overlap > 0 ) {
78+ var currentTop = parseFloat ( getComputedStyle ( notes [ i ] ) . top ) || 0 ;
79+ notes [ i ] . style . top = ( currentTop + overlap + 8 ) + 'px' ;
80+ }
81+ }
5882 } ) ;
5983} ) ;
0 commit comments