# Convert specia characters to their HTML codes html::encode () { $SED ' s|\&|\&|g; s|<|\<|g; s|>|\>|g; s|'\''|\'|g; ' <<< "$@" } # Make a HTML paragraph. html::make_paragraph () { local -r text="$1"; shift if [ "$HTML_VARIANT_TO_USE" = exact ]; then if [ -n "$text" ]; then echo "$(html::encode "$text")
" else echo '
' fi elif [ -n "$text" ]; then echo "

$(html::encode "$text")

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

$(html::encode "$quote")

" fi } # Make a HTML image html::make_img () { local link="$1"; shift local descr="$1"; shift if [ -z "$descr" ]; then echo "
" else echo "$descr
" fi } # Make a HTML hyperlink html::make_link () { local link="$1"; shift local descr="$1"; shift if ! $GREP -F -q '://' <<< "$link"; then link=${link/.gmi/.html} fi if [[ -z "$descr" ]]; then descr="$link" fi local mastodon_verify='' if [[ "$link" = "$MASTODON_URI" ]]; then mastodon_verify=" rel='me'" fi echo "$descr
" } html::process_inline () { $SED -E "s|\`([^\`]+)\`|\\1|g" } html::add_extras () { local -r html_base_dir="$CONTENT_BASE_DIR/html" cp "$HTML_CSS_STYLE" "$html_base_dir/style.css" while read -r section_dir; do local override_source="./extras/html/style-$(basename "$section_dir")-override.css" local override_dest="$section_dir/style-override.css" if [ ! -f "$override_source" ]; then touch "$override_dest" # Empty override else cp "$override_source" "$override_dest" fi done < <(find "$html_base_dir" -mindepth 1 -maxdepth 1 -type d | $GREP -E -v '(\.git)') if [ -f "$HTML_WEBFONT_TEXT" ]; then cp "$HTML_WEBFONT_TEXT" "$html_base_dir/text.ttf" fi if [ -f "$HTML_WEBFONT_CODE" ]; then cp "$HTML_WEBFONT_CODE" "$html_base_dir/code.ttf" fi if [ -f "$HTML_WEBFONT_HANDNOTES" ]; then cp "$HTML_WEBFONT_HANDNOTES" "$html_base_dir/handnotes.ttf" fi if [ -f "$HTML_WEBFONT_TYPEWRITER" ]; then cp "$HTML_WEBFONT_TYPEWRITER" "$html_base_dir/typewriter.ttf" fi } html::source_highlight () { local -r bare_text="$1"; shift local -r language="$1"; shift if [[ -z "$language" || -z "$SOURCE_HIGHLIGHT" ]]; then echo '
'
        html::encode "$bare_text"
        echo '
' else $SOURCE_HIGHLIGHT --src-lang="$language" <<< "$bare_text" | $SED 's|||; s|||;' fi } # Convert Gemtext to HTML html::fromgmi () { local is_list=no local is_bare=no local bare_text='' local language='' while IFS='' read -r line; do if [[ "$is_list" == yes ]]; then if [[ "$line" == '* '* ]]; then echo "
  • $(html::encode "${line/\* /}")
  • " | html::process_inline else is_list=no if [ "$HTML_VARIANT_TO_USE" = exact ]; then echo "
    " else echo "" fi fi continue elif [[ "$is_bare" == yes ]]; then if [[ "$line" == '```'* ]]; then html::source_highlight "$bare_text" "$language" is_bare=no bare_text='' language='' elif [ -z "$bare_text" ]; then bare_text="$line" else bare_text="$bare_text $line" fi continue fi case "$line" in '* '*) is_list=yes echo "