From a453bf2f909e0ea01b0649ce8dc42d54689f738f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 11 May 2021 19:54:23 +0100 Subject: refactor --- modules/html.source.sh | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 modules/html.source.sh (limited to 'modules/html.source.sh') diff --git a/modules/html.source.sh b/modules/html.source.sh new file mode 100644 index 0000000..9fb4a30 --- /dev/null +++ b/modules/html.source.sh @@ -0,0 +1,147 @@ +html::special () { + $SED ' + s|\&|\&|g; + s|<|\<|g; + s|>|\>|g; + ' <<< "$@" +} + +html::make_paragraph () { + local -r text="$1"; shift + test -n "$text" && echo "

$(html::special "$text")

" +} + +html::make_heading () { + local -r text=$($SED -E 's/^#+ //' <<< "$1"); shift + local -r level="$1"; shift + + echo "$(html::special "$text")" +} + +html::make_quote () { + local -r quote="${1/> }" + echo "
$(html::special "$quote")
" +} + +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 "
" +} + +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
" +} + +html::fromgmi () { + local -r gmi_file=$1 + local -i is_list=0 + local -i is_plain=0 + + while IFS='' read -r line; do + if [ $is_list -eq 1 ]; then + if [[ "$line" == '* '* ]]; then + echo "
  • ${line/\* /}
  • " + else + is_list=0 + echo "" + fi + continue + + elif [ $is_plain -eq 1 ]; then + if [[ "$line" == '```'* ]]; then + echo "" + is_plain=0 + else + html::special "$line" + fi + continue + fi + + case "$line" in + '* '*) + is_list=1 + echo "