@@ -89,34 +89,49 @@ jobs:
8989 # Process HTML img tags separately - preserving all attributes
9090 echo "Processing HTML image references..."
9191
92- # Use a more robust method to process HTML img tags
93- # Create a temporary file for processing
92+ # Use a more reliable approach with temporary files and simpler perl commands
9493 temp_file=$(mktemp)
9594 echo "$content" > "$temp_file"
9695
97- # Process each img tag properly with perl
98- perl -i -0777 -pe '
99- while (s/(<img\s+[^>]*?src=")([^"]+)("[^>]*?>)/) {
100- my $prefix = $1;
101- my $src = $2;
102- my $suffix = $3;
103-
104- # Skip URLs
105- if ($src =~ /^http/) {
106- # Do nothing, keep as is
107- } else {
108- # Path to be replaced
109- my $filename = $src;
110- $filename =~ s/.*\///; # Extract filename
111- my $new_path = "images/" . $filename;
112- $_ = $` . $prefix . $new_path . $suffix . $`;
113- }
114- }
115- ' "$temp_file"
96+ # Create a simpler perl script file instead of inline perl
97+ perl_script=$(mktemp)
98+ # Write the perl script with proper escaping for YAML
99+ cat > "$perl_script" << 'PERLSCRIPT'
100+ # !/usr/bin/perl
101+ use strict;
102+ use warnings;
103+
104+ my $content = do { local $/; <STDIN> };
105+
106+ # Process HTML img tags
107+ while ($content =~ m|(<img\s+[^>]*?src=")([^"]+)("[^>]*?>)|g) {
108+ my $prefix = $1;
109+ my $src = $2;
110+ my $suffix = $3;
111+ my $tag = $prefix . $src . $suffix;
112+
113+ # Skip URLs
114+ next if $src =~ /^http/;
115+
116+ # Get just the filename
117+ my $filename = $src;
118+ $filename =~ s/.*\///;
119+ my $new_path = "images/" . $filename;
120+
121+ # Replace in content
122+ my $new_tag = $prefix . $new_path . $suffix;
123+ $content =~ s/\Q$tag\E/$new_tag/g;
124+ }
125+
126+ print $content;
127+ PERLSCRIPT
128+
129+ # Process content with the perl script
130+ cat "$temp_file" | perl "$perl_script" > "${temp_file}.new"
131+ content=$(cat "${temp_file}.new")
116132
117- # Read back the processed content
118- content=$(cat "$temp_file")
119- rm "$temp_file" # Clean up
133+ # Clean up temporary files
134+ rm "$temp_file" "${temp_file}.new" "$perl_script"
120135
121136 # Now copy all the images referenced in HTML tags
122137 for img_src in $(grep -o '<img [^>]*src="[^"]*"' "./$rel_path" | sed -E 's/.*src="([^"]*)".*/\1/'); do
0 commit comments