From d8d6f8e02911bf2d1df0ef272ac9f188a0fec498 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 7 Apr 2026 12:15:17 -0700 Subject: [PATCH 1/2] Improvements from Claude --- hevea-add-verbatim-linenos | 2 +- html-update-link-dates | 2 +- html-update-toc | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hevea-add-verbatim-linenos b/hevea-add-verbatim-linenos index f3dcc3c..56154c0 100755 --- a/hevea-add-verbatim-linenos +++ b/hevea-add-verbatim-linenos @@ -45,4 +45,4 @@ def replace_line(match: re.Match[str]) -> str: with Path(htmlfile).open() as htmlfile_handle: for line in htmlfile_handle: line = lineref_re.sub(replace_line, line) - print(line) + print(line, end="") diff --git a/html-update-link-dates b/html-update-link-dates index af2111f..9de9c8d 100755 --- a/html-update-link-dates +++ b/html-update-link-dates @@ -181,7 +181,7 @@ sub file_size ( $ ) # 5 to the third most significant digit (since we truncate to two # significant digits). my $to_add = "5" . ("0" x (length($size) - 3)); - $trunc_size = sprintf("%f", ($size + $to_add) / $divisor); + my $trunc_size = sprintf("%f", ($size + $to_add) / $divisor); if ($trunc_size =~ m/^([0-9][0-9])([0-9]*)(\.[0-9]*)?$/) { $trunc_size = $1 . "0" x length($2); diff --git a/html-update-toc b/html-update-toc index 765c8fc..177a581 100755 --- a/html-update-toc +++ b/html-update-toc @@ -101,7 +101,7 @@ FILELOOP: for my $file (@ARGV) } next; } - if (!open(FILE, $file)) + if (!open(FILE, '<', $file)) { print STDERR "Skipping $file: can't open\n"; next; @@ -131,7 +131,10 @@ FILELOOP: for my $file (@ARGV) if ($line =~ /($contents_start)(.*?)($contents_end)/is) { my $oldcontent = $2; - my $newcontent = `$script_dir/html-toc $file`; + open(my $toc_pipe, '-|', "$script_dir/html-toc", $file) + or die "Can't run html-toc: $!"; + my $newcontent = do { local $/; <$toc_pipe> }; + close($toc_pipe); if ($newcontent eq "\n") { $newcontent = ""; @@ -156,9 +159,9 @@ FILELOOP: for my $file (@ARGV) # "perl -pi.bak -e '\$/ = \"\\n\\n\"; s/($contents_start_quoted)(.*?)($contents_end_quoted)/\$1$newcontent_quoted\$3/s'" # but that doesn't work: the shell says "word too long". rename($file, "$file.bak") or die "Can't make backup of $file"; - open(OLDFILE, "$file.bak") + open(OLDFILE, '<', "$file.bak") or die "Can't read backup I just made: $file.bak"; - open(FILE, ">$file") + open(FILE, '>', $file) or die "Can't write $file; old version in $file.bak"; while (defined($line = )) { From 7d3312929d7d3d569dde6e42e6e0f3fd7e2c27f4 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Tue, 7 Apr 2026 12:33:14 -0700 Subject: [PATCH 2/2] CodeRabbit suggestion --- html-update-toc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/html-update-toc b/html-update-toc index 177a581..d0e5f9f 100755 --- a/html-update-toc +++ b/html-update-toc @@ -134,7 +134,10 @@ FILELOOP: for my $file (@ARGV) open(my $toc_pipe, '-|', "$script_dir/html-toc", $file) or die "Can't run html-toc: $!"; my $newcontent = do { local $/; <$toc_pipe> }; - close($toc_pipe); + close($toc_pipe) or die( + $! ? "Error closing pipe: $!" + : "html-toc failed for $file (exit status: $?)" + ); if ($newcontent eq "\n") { $newcontent = "";