# 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")$(html::encode "$quote")
" fi } # Make a HTML image html::make_img () { local link="$1"; shift local descr="$1"; shift if [ -z "$descr" ]; 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 "Hello world! This is a paragraph.
' line='' assert::equals "$(html::make_paragraph "$line")" '' line='Foo &<>& Bar!' assert::equals "$(html::make_paragraph "$line")" 'Foo &<>& Bar!
' line='echo foo 2>&1' assert::equals "$(html::make_paragraph "$line")" 'echo foo 2>&1
' line='> This is a quote' assert::equals "$(html::make_quote "$line")" "This is a quote
" line='Testing: `hello_world.sh --debug` :-) `another one`!' assert::equals "$(echo "$line" | html::process_inline)" \ "Testing: hello_world.sh --debug :-) another one!" line='=> https://example.org' assert::equals "$(generate::make_link html "$line")" \ "https://example.org

this
is
a
bare block
'
assert::equals "$(html::fromgmi <<< "$input_block")" "$output_block"
if [ -n "$SOURCE_HIGHLIGHT" ]; then
input_block='```bash
if [ -z $foo ]; then
echo $foo
fi
```'
assert::contains "$(html::fromgmi <<< "$input_block")" 'GNU source-highlight'
fi
}
# Test exact HTML variant.
html::test::exact () {
local line='Hello world! This is a paragraph.'
assert::equals "$(html::make_paragraph "$line")" "Hello world! This is a paragraph.