@@ -89,45 +89,62 @@ jobs:
89
89
# Process HTML img tags separately using grep and sed instead of perl
90
90
echo "Processing HTML image references..."
91
91
92
+ # Save original content for processing
93
+ original_content="$content"
94
+
92
95
# Extract all HTML img tags with their src attributes
93
- img_tags=$(grep -o '<img [^>]*src="[^"]*"[^>]*>' "./$rel_path" || echo "")
96
+ # Use a temporary file to store unique img tags since they might be multi-line
97
+ temp_file=$(mktemp)
98
+ grep -o '<img[^>]*>' "./$rel_path" > "$temp_file" || echo "" > "$temp_file"
94
99
95
- if [ ! -z "$img_tags" ]; then
96
- # For each image tag
97
- echo "$img_tags" | while read -r img_tag; do
98
- # Extract the src attribute
99
- img_src=$(echo "$img_tag" | sed -E 's/.*src="([^"]*)".*/\1/')
100
-
101
- # Skip URLs
102
- if [[ $img_src == http* ]]; then
103
- continue
104
- fi
100
+ # Process each img tag from the file
101
+ while IFS= read -r img_tag; do
102
+ # Skip if empty
103
+ if [ -z "$img_tag" ]; then
104
+ continue
105
+ fi
106
+
107
+ # Extract the src attribute
108
+ img_src=$(echo "$img_tag" | sed -n 's/.*src="\([^"]*\)".*/\1/p')
109
+
110
+ # Skip if no src or if it's a URL
111
+ if [ -z "$img_src" ] || [[ $img_src == http* ]]; then
112
+ continue
113
+ fi
114
+
115
+ # Determine the absolute path of the image
116
+ if [[ $img_src == /* ]]; then
117
+ abs_img_path="./$img_src"
118
+ else
119
+ abs_img_path="$base_dir/$img_src"
120
+ fi
121
+
122
+ # Extract just the filename
123
+ img_filename=$(basename "$img_src")
124
+ wiki_img_path="images/$img_filename"
125
+
126
+ # Copy the image to wiki repository if it exists
127
+ if [ -f "$abs_img_path" ]; then
128
+ echo "Copying image: $abs_img_path -> ./wiki/$wiki_img_path"
129
+ cp -v "$abs_img_path" "./wiki/$wiki_img_path" || echo "Error copying image"
105
130
106
- # Determine the absolute path of the image
107
- if [[ $img_src == /* ]]; then
108
- abs_img_path="./$img_src"
109
- else
110
- abs_img_path="$base_dir/$img_src"
111
- fi
131
+ # Create a new img tag with the updated src but preserving all other attributes
132
+ new_img_tag=$(echo "$img_tag" | sed "s|src=\"$img_src\"|src=\"$wiki_img_path\"|g")
112
133
113
- # Extract just the filename
114
- img_filename =$(basename "$img_src" )
115
- wiki_img_path="images/$img_filename"
134
+ # Escape special characters for sed replacement
135
+ escaped_img_tag =$(echo "$img_tag" | sed 's/[\/&]/\\&/g' )
136
+ escaped_new_img_tag=$(echo "$new_img_tag" | sed 's/[\/&]/\\&/g')
116
137
117
- # Copy the image to wiki repository if it exists
118
- if [ -f "$abs_img_path" ]; then
119
- echo "Copying image: $abs_img_path -> ./wiki/$wiki_img_path"
120
- cp -v "$abs_img_path" "./wiki/$wiki_img_path" || echo "Error copying image"
121
-
122
- # Safely replace the image reference in content
123
- escaped_src=$(echo "$img_src" | sed 's/[\/&]/\\&/g')
124
- escaped_wiki_path=$(echo "$wiki_img_path" | sed 's/[\/&]/\\&/g')
125
- content=$(echo "$content" | sed "s|src=\"$escaped_src\"|src=\"$escaped_wiki_path\"|g")
126
- else
127
- echo "Warning: HTML image file not found: $abs_img_path"
128
- fi
129
- done
130
- fi
138
+ # Replace the img tag in content
139
+ content=$(echo "$content" | sed "s|$escaped_img_tag|$escaped_new_img_tag|g")
140
+ echo "Replaced HTML image tag with new src path while preserving style attributes"
141
+ else
142
+ echo "Warning: HTML image file not found: $abs_img_path"
143
+ fi
144
+ done < "$temp_file"
145
+
146
+ # Clean up temporary file
147
+ rm "$temp_file"
131
148
132
149
# Debug output
133
150
echo "Wiki page content preview (first 100 chars): ${content:0:100}"
0 commit comments