From f8ed501b9e61e366c37b4cc6899abc7cd511d32b Mon Sep 17 00:00:00 2001 From: D5k H3h <85834680+dhuschde@users.noreply.github.com> Date: Tue, 21 Jan 2025 00:01:32 +0100 Subject: [PATCH] fixing bugs --- memes.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/memes.sh b/memes.sh index 0191c55..ccdc31b 100644 --- a/memes.sh +++ b/memes.sh @@ -75,6 +75,16 @@ alt=$(echo "$alt" | sed -e 's/

/\n/g' -e 's/<\/p>/\n/g' -e 's/<[^>]*>//g' -e ' alt=$(echo "$alt" | sed 's/ */ /g' | sed 's/^ //;s/ $//') alt=$(echo "$alt" | sed 's/^"//;s/"$//') alt=$(echo "$alt" | sed 's/\\"/"/g') +alt=$(printf '%q' "$alt") + +# Step 1: Replace newlines with a placeholder +alt=$(echo "$alt" | sed ':a;N;$!ba;s/\n/PLACEHOLDER_NEWLINE/g') + +# Step 2: Escape the string using jq +alt=$(jq -Rn --arg alt "$alt" '$alt') + +# Step 3: Restore newlines +alt=$(echo "$alt" | sed 's/PLACEHOLDER_NEWLINE/\n/g') echo "Adding alt Text" echo $alt