various fixes for the h4 support

This commit is contained in:
OniriCorpe 2024-04-30 01:59:03 +02:00
parent d55460cded
commit 2fef20f836

View file

@ -72,15 +72,18 @@ do
# converting .gmi files in .html
/usr/local/bin/gmnitohtml < "$gmi_file" > "$tempdir/body.html"
cp "$tempdir/body.html" "$tempdir/work-body.html"
# trick to support h4 titles
lines=$(grep "<h3># .*<\/h3>" "$tempdir/body.html")
while read -r line; do
fixed_line=${line//<h3># /<h4>} # replace '<h3># ' by '<h4>'
fixed_line=${fixed_line//<\/h3>/<\/h4>} # replace '</h3>' by '</h4>'
# shellcheck disable=SC2001
fixed_line=$(echo "$fixed_line" | sed "s#&#\\\&#g") # escape eventual '&'
sed -i "s^${line}^${fixed_line}^" "$tempdir/body.html"
done <<< "$lines"
while IFS= read -r line; do
if echo $ "$line" | grep -q "<h3># .*<\/h3>"; then
fixed_line=${line//<h3># /<h4>} # replace '<h3># ' by '<h4>'
fixed_line=${fixed_line//<\/h3>/<\/h4>} # replace '</h3>' by '</h4>'
# shellcheck disable=SC2001
fixed_line=$(echo "$fixed_line" | sed "s#&#\\\&#g") # escape eventual '&'
sed -i "s^${line}^${fixed_line}^" "$tempdir/body.html"
fi
done < "$tempdir/work-body.html"
# retrieving of the path of the current .gmi file
file_path="$(dirname "$gmi_file")"