@@ -88,59 +88,62 @@ jobs:
8888
8989 # Process HTML img tags separately - preserving all attributes
9090 echo "Processing HTML image references..."
91- # Store the file content in a temporary variable to process with awk
92- readme_content=$(cat "./$rel_path")
9391
94- # Use awk to find all img tags and process them
95- img_tags=$(echo "$readme_content" | grep -o '<img[^>]*>' || echo "")
96- if [ -n "$img_tags" ]; then
97- echo "Found HTML img tags to process"
98- echo "$img_tags" | while read -r img_tag; do
99- # Extract src attribute
100- img_src=$(echo "$img_tag" | grep -o 'src="[^"]*"' | sed 's/src="\([^"]*\)"/\1/')
101-
102- # Skip if no src or if it's a URL
103- if [ -z "$img_src" ] || [[ $img_src == http* ]]; then
104- continue
105- fi
106-
107- # Determine the absolute path of the image
108- if [[ $img_src == /* ]]; then
109- # Absolute path within repository
110- abs_img_path="./$img_src"
111- else
112- # Relative path to the README
113- abs_img_path="$base_dir/$img_src"
114- fi
115-
116- # Extract just the filename
117- img_filename=$(basename "$img_src")
118- wiki_img_path="images/$img_filename"
92+ # Use a more robust method to process HTML img tags
93+ # Create a temporary file for processing
94+ temp_file=$(mktemp)
95+ echo "$content" > "$temp_file"
96+
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;
119103
120- # Copy the image to wiki repository if it exists
121- if [ -f "$abs_img_path" ]; then
122- echo "Copying image: $abs_img_path -> ./wiki/$wiki_img_path"
123- cp -v "$abs_img_path" "./wiki/$wiki_img_path" || echo "Error copying image"
124-
125- # Escape special characters in the path for sed
126- escaped_img_src=$(echo "$img_src" | sed 's/[\/&]/\\&/g')
127- escaped_img_tag=$(echo "$img_tag" | sed 's/[\/&]/\\&/g')
128-
129- # Create the new tag with the updated src but preserving all other attributes
130- new_img_tag=$(echo "$img_tag" | sed "s|src=\"$escaped_img_src\"|src=\"$wiki_img_path\"|g")
131-
132- # Replace the entire img tag in content
133- content=$(echo "$content" | sed "s|$escaped_img_tag|$new_img_tag|g")
134- echo "Replaced HTML image tag while preserving all attributes"
135- else
136- echo "Warning: HTML image file not found: $abs_img_path"
137- # Add more debug info
138- echo "Current directory: $(pwd)"
139- echo "Files in $base_dir:"
140- ls -la "$base_dir"
141- fi
142- done
143- fi
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"
116+
117+ # Read back the processed content
118+ content=$(cat "$temp_file")
119+ rm "$temp_file" # Clean up
120+
121+ # Now copy all the images referenced in HTML tags
122+ for img_src in $(grep -o '<img [^>]*src="[^"]*"' "./$rel_path" | sed -E 's/.*src="([^"]*)".*/\1/'); do
123+ # Skip URLs
124+ if [[ $img_src == http* ]]; then
125+ continue
126+ fi
127+
128+ # Determine the absolute path of the image
129+ if [[ $img_src == /* ]]; then
130+ abs_img_path="./$img_src"
131+ else
132+ abs_img_path="$base_dir/$img_src"
133+ fi
134+
135+ # Extract just the filename
136+ img_filename=$(basename "$img_src")
137+ wiki_img_path="images/$img_filename"
138+
139+ # Copy the image to wiki repository if it exists
140+ if [ -f "$abs_img_path" ]; then
141+ echo "Copying image: $abs_img_path -> ./wiki/$wiki_img_path"
142+ cp -v "$abs_img_path" "./wiki/$wiki_img_path" || echo "Error copying image"
143+ else
144+ echo "Warning: HTML image file not found: $abs_img_path"
145+ fi
146+ done
144147
145148 # Debug output
146149 echo "Wiki page content preview (first 100 chars): ${content:0:100}"
0 commit comments