diff --git a/fix-link.sh b/fix-link.sh index 558d19ed4..b321a945a 100755 --- a/fix-link.sh +++ b/fix-link.sh @@ -44,21 +44,28 @@ while IFS=':' read -r file_path line_err status desc data; do if [ "$desc" = "undefined label" ]; then echo -e "${GRAY}DEBUG: Found 'undefined label' case${NC}" - # Replace \, /, or _ with - in data - new_data=$(echo "$data" | tr '\\/_' '-') - echo -e "${GRAY}DEBUG: Changing '$data' to '$new_data'${NC}" + # Check if data is enclosed in < and > + if [[ "$data" =~ ^\<.*\>$ ]]; then + # Remove < and > for processing + clean_data=$(echo "$data" | sed 's/^$//') + # Replace \, /, or _ with - in clean_data + new_data=$(echo "$clean_data" | tr '\\/_' '-') + echo -e "${GRAY}DEBUG: Changing '$data' to '<$new_data>'${NC}" - # Check if the data appears in an {image} directive - if grep -B1 "$data" "$file_path" | grep -q "{image}"; then - echo -e "${GRAY}DEBUG: Skipping '$data' as it appears in an {image} directive${NC}" - else - # Replace the old data with new data in the file, only if not preceded by {image} - if sed -i "/{image}/!s|$data|$new_data|g" "$file_path" 2>/dev/null; then - changes_made=$((changes_made + 1)) - echo -e "${GREEN}Processed: $file_path - Changed '$data' to '$new_data'${NC}" + # Check if the data appears in an {image} directive + if grep -B1 "$data" "$file_path" | grep -q "{image}"; then + echo -e "${GRAY}DEBUG: Skipping '$data' as it appears in an {image} directive${NC}" else - echo -e "${RED}WARNING: Failed to modify $file_path${NC}" + # Replace the old data with new data in the file, only if not preceded by {image} + if sed -i "/{image}/!s|$data|<$new_data>|g" "$file_path" 2>/dev/null; then + changes_made=$((changes_made + 1)) + echo -e "${GREEN}Processed: $file_path - Changed '$data' to '<$new_data>'${NC}" + else + echo -e "${RED}WARNING: Failed to modify $file_path${NC}" + fi fi + else + echo -e "${GRAY}DEBUG: Skipping '$data' as it is not enclosed in <>${NC}" fi elif [[ "$desc" =~ "toctree contains reference to nonexisting document" ]]; then