From 88be39ae445cf41adb1c0c79876be808afb20d6d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 6 Apr 2023 23:19:54 +0300 Subject: add HTML exact variant --- lib/html.source.sh | 107 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 34 deletions(-) (limited to 'lib') diff --git a/lib/html.source.sh b/lib/html.source.sh index d99220b..c2cf13c 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -11,7 +11,13 @@ html::encode () { html::make_paragraph () { local -r text="$1"; shift - if [[ -n "$text" ]]; then + 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 } @@ -20,13 +26,23 @@ html::make_paragraph () { html::make_heading () { local -r text=$($SED -E 's/^#+ //' <<< "$1"); shift local -r level="$1"; shift - echo "$(html::encode "$text")" + + 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/> }" - echo "

$(html::encode "$quote")

" + if [ "$HTML_VARIANT_TO_USE" = exact ]; then + echo "$(html::encode "$quote")
" + else + echo "

$(html::encode "$quote")

" + fi } # Make a HTML image @@ -35,12 +51,12 @@ html::make_img () { local descr="$1"; shift if [ -z "$descr" ]; then - echo -n "" + echo -n "" else - echo -n "\"$descr\"" + echo -n "$descr" fi - echo "
" + echo '
' } # Make a HTML hyperlink @@ -56,17 +72,11 @@ html::make_link () { descr="$link" fi - echo "$descr
" -} - -# Make inline code! -html::process_inline_code () { - $SED -E 's|`([^`]+)`|\1|g' + echo "$descr
" } html::process_inline () { - # As of now we only inlinde "code blocks", but we can chain more here later! - html::process_inline_code + $SED -E 's|`([^`]+)`|\1|g' } html::add_extras () { @@ -82,6 +92,7 @@ html::add_extras () { cp "$override_source" "$override_dest" fi done < <(find "$html_base_dir" -mindepth 1 -maxdepth 1 -type d | $GREP -E -v '(\.git)') + cp "$HTML_WEBFONT_TEXT" "$html_base_dir/text.ttf" cp "$HTML_WEBFONT_CODE" "$html_base_dir/code.ttf" cp "$HTML_WEBFONT_HANDNOTES" "$html_base_dir/handnotes.ttf" @@ -100,7 +111,11 @@ html::fromgmi () { html::process_inline else is_list=no - echo "" + if [ "$HTML_VARIANT_TO_USE" = exact ]; then + echo "
" + else + echo "" + fi fi continue @@ -151,8 +166,8 @@ html::fromgmi () { done } -# Test HTML package. -html::test () { +# Test default HTML variant. +html::test::default () { local line='Hello world! This is a paragraph.' assert::equals "$(html::make_paragraph "$line")" '

Hello world! This is a paragraph.

' @@ -165,39 +180,63 @@ html::test () { line='echo foo 2>&1' assert::equals "$(html::make_paragraph "$line")" '

echo foo 2>&1

' - line='# Header 1' - assert::equals "$(html::make_heading "$line" 1)" '

Header 1

' - - line='## Header 2' - assert::equals "$(html::make_heading "$line" 2)" '

Header 2

' - - line='### Header 3' - assert::equals "$(html::make_heading "$line" 3)" '

Header 3

' - line='> This is a quote' - assert::equals "$(html::make_quote "$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_code)" \ - '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
' + "https://example.org
" line='=> index.html' assert::equals "$(generate::make_link html "$line")" \ - 'index.html
' + "index.html
" line='=> http://example.org Description of the link' assert::equals "$(generate::make_link html "$line")" \ - 'Description of the link
' + "Description of the link
" line='=> http://example.org/image.png' assert::equals "$(generate::make_link html "$line")" \ - '
' + "
" line='=> http://example.org/image.png Image description' assert::equals "$(generate::make_link html "$line")" \ - 'Image description
' + "Image description
" +} + +# 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.
" + + 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='# Header 1' + assert::equals "$(html::make_heading "$line" 1)" "

Header 1


" + + line='## Header 2' + assert::equals "$(html::make_heading "$line" 2)" "

Header 2


" + + line='### Header 3' + assert::equals "$(html::make_heading "$line" 3)" "

Header 3


" + + + line='> This is a quote' + assert::equals "$(html::make_quote "$line")" "This is a quote
" +} + +html::test () { + HTML_VARIANT_TO_USE=default html::test::default + HTML_VARIANT_TO_USE=exact html::test::exact } -- cgit v1.2.3