source: trunk/doc-new/toc-for-chunked.tcl @ 154113

Last change on this file since 154113 was 154113, checked in by raimue@…, 4 years ago

guide: escape string for regex replace

Special characters such as '&' could trigger strange behavior as they were
interpreted by the regex engine.

File size: 761 bytes
[38342]1# Adds the table of contents to every file of the chunked documentation.
4# Get the table of contents from the index.html file and create the
5# replacement string.
6set file [open "[lindex $argv 0]/index.html"]
7regexp {<div class="toc">.+?</div>} [read $file] replacement
8close $file
[120885]9set replacement "<body\\1><div class=\"book\">$replacement"
11# Add the table of contents to all other html files.
[38440]12foreach path [glob -directory [lindex $argv 0] {*.html}] {
[120885]13    if {[file tail $path] == "index.html"} {
[38440]14        continue
15    }
[38342]17    set file [open $path r+]
18    set data [read $file]
[154113]19    regsub {<body([^>]+)>} $data [regsub -all {\W} $replacement {\\&}] data
[38342]20    regsub {</body>} $data {</div></body>} data
21    seek $file 0
22    puts $file $data
23    close $file
Note: See TracBrowser for help on using the repository browser.