You've already forked macports-guide
mirror of
https://github.com/macports/macports-guide.git
synced 2026-07-12 18:18:46 -07:00
Properly escape string for regex replace
Only escape special replacement syntax such as \0 or & in the
replacement string.
This is a follow-up to 265dc92b95 which
broke the TOC output.
Closes: https://trac.macports.org/ticket/52924
This commit is contained in:
+2
-2
@@ -6,7 +6,7 @@
|
||||
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\">$replacement"
|
||||
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}] {
|
||||
@@ -16,7 +16,7 @@ foreach path [glob -directory [lindex $argv 0] {*.html}] {
|
||||
|
||||
set file [open $path r+]
|
||||
set data [read $file]
|
||||
regsub {<body([^>]+)>} $data [regsub -all {\W} $replacement {\\&}] data
|
||||
regsub {<body([^>]+)>} $data $replacement data
|
||||
regsub {</body>} $data {</div></body>} data
|
||||
seek $file 0
|
||||
puts $file $data
|
||||
|
||||
Reference in New Issue
Block a user