-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
toc-for-chunked.tcl
24 lines (20 loc) · 768 Bytes
/
toc-for-chunked.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Adds the table of contents to every file of the chunked documentation.
# Get the table of contents from the index.html file and create the
# replacement string.
set file [open "[lindex $argv 0]/index.html"]
regexp {<div class="toc">.+?</div>} [read $file] replacement
close $file
set replacement "<body\\1><div class=\"book\">[regsub -all {&|\\[0-9]} $replacement {\\&}]"
# Add the table of contents to all other html files.
foreach path [glob -directory [lindex $argv 0] {*.html}] {
if {[file tail $path] == "index.html"} {
continue
}
set file [open $path r+]
set data [read $file]
regsub {<body([^>]+)>} $data $replacement data
regsub {</body>} $data {</div></body>} data
seek $file 0
puts $file $data
close $file
}