# Convert special characters to their HTML codes html::encode () { $SED ' s|\&|\&|g; s|<|\<|g; s|>|\>|g; ' <<< "$@" } # Make a HTML paragraph. html::make_paragraph () { local -r text="$1"; shift test -n "$text" && echo "

$(html::encode "$text")

" } # Make a HTML header. html::make_heading () { local -r text=$($SED -E 's/^#+ //' <<< "$1"); shift local -r level="$1"; shift echo "$(html::encode "$text")" } # Make a HTML quotation html::make_quote () { local -r quote="${1/> }" echo "

$(html::encode "$quote")

" } # Make a HTML image html::make_img () { local link="$1"; shift local descr="$1"; shift if [ -z "$descr" ]; then echo -n "" else echo -n "$descr:" echo -n "\"$descr\"" fi echo "
" } # Make a HTML hyperlink html::make_link () { local link="$1"; shift local descr="$1"; shift $GREP -F -q '://' <<< "$link" || link=${link/.gmi/.html} test -z "$descr" && descr="$link" echo "$descr
" } # Convert Gemtext to HTML html::fromgmi () { local is_list=no local is_plain=no while IFS='' read -r line; do if [[ "$is_list" == yes ]]; then if [[ "$line" == '* '* ]]; then echo "
  • $(html::encode "${line/\* /}")
  • " else is_list=no echo "" fi continue elif [[ "$is_plain" == yes ]]; then if [[ "$line" == '```'* ]]; then echo "" is_plain=no else html::encode "$line" fi continue fi case "$line" in '* '*) is_list=yes echo "