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 From 1077678711fca18792080b80f3bf7cae3fc4e70d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 7 Apr 2023 00:48:49 +0300 Subject: make ttf optional --- lib/html.source.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/html.source.sh b/lib/html.source.sh index c2cf13c..0e99853 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -51,12 +51,10 @@ html::make_img () { local descr="$1"; shift if [ -z "$descr" ]; then - echo -n "" + echo "
" else - echo -n "$descr" + echo "$descr
" fi - - echo '
' } # Make a HTML hyperlink @@ -93,10 +91,18 @@ html::add_extras () { 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" - cp "$HTML_WEBFONT_TYPEWRITER" "$html_base_dir/typewriter.ttf" + 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 } # Convert Gemtext to HTML -- cgit v1.2.3 From fed1dbf0d164a18b01843323b676d1bff3f628da Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 8 Apr 2023 12:34:39 +0300 Subject: make validator.w3.org happy about XHTML --- lib/html.source.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/html.source.sh b/lib/html.source.sh index 0e99853..e148ef1 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -28,7 +28,7 @@ html::make_heading () { local -r level="$1"; shift if [ "$HTML_VARIANT_TO_USE" = exact ]; then - #echo "$(html::encode "$text")
" + #echo "$(html::encode "$text")
" echo "$(html::encode "$text")
" else echo "$(html::encode "$text")
" @@ -39,9 +39,9 @@ html::make_heading () { html::make_quote () { local -r quote="${1/> }" if [ "$HTML_VARIANT_TO_USE" = exact ]; then - echo "$(html::encode "$quote")
" + echo "$(html::encode "$quote")
" else - echo "

$(html::encode "$quote")

" + echo "

$(html::encode "$quote")

" fi } @@ -70,11 +70,11 @@ html::make_link () { descr="$link" fi - echo "$descr
" + echo "$descr
" } html::process_inline () { - $SED -E 's|`([^`]+)`|\1|g' + $SED -E "s|\`([^\`]+)\`|\\1|g" } html::add_extras () { @@ -187,23 +187,23 @@ html::test::default () { 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

" + 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!" + "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")" \ @@ -239,7 +239,7 @@ html::test::exact () { 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
" } html::test () { -- cgit v1.2.3 From b253915c629c6d38641a81c7f1bb47d662c48a03 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 9 Apr 2023 13:21:29 +0300 Subject: add support for GNU Source Highlight - for Source code highlighting in bare blocks --- lib/assert.source.sh | 14 +++++++++++ lib/html.source.sh | 69 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/assert.source.sh b/lib/assert.source.sh index a1713c3..990194c 100644 --- a/lib/assert.source.sh +++ b/lib/assert.source.sh @@ -31,6 +31,20 @@ assert::not_empty () { log VERBOSE "Result in $callee as expected not empty" } +# Unit test for whether a given string contains a substring +assert::contains () { + local -r content="$1"; shift + local -r substring="$1"; shift + local -r callee=${FUNCNAME[1]} + + if ! $GREP -q -F "$substring" <<< "$content"; then + log ERROR "In $callee expected '$content' to contain substring '$substring'" + exit 2 + fi + + log VERBOSE "Substring check in $callee as expected, contains '$substring'" +} + # Unit test for whether a given string matches a regex. assert::matches () { local -r name="$1"; shift diff --git a/lib/html.source.sh b/lib/html.source.sh index e148ef1..7056f24 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -1,4 +1,4 @@ -# Convert special characters to their HTML codes +# Convert specia characters to their HTML codes html::encode () { $SED ' s|\&|\&|g; @@ -105,10 +105,26 @@ html::add_extras () { 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_plain=no + local is_bare=no + local bare_text='' + local language='' while IFS='' read -r line; do if [[ "$is_list" == yes ]]; then @@ -125,12 +141,17 @@ html::fromgmi () { fi continue - elif [[ "$is_plain" == yes ]]; then + elif [[ "$is_bare" == yes ]]; then if [[ "$line" == '```'* ]]; then - echo "" - is_plain=no + html::source_highlight "$bare_text" "$language" + is_bare=no + bare_text='' + language='' + elif [ -z "$bare_text" ]; then + bare_text="$line" else - html::encode "$line" + bare_text="$bare_text +$line" fi continue fi @@ -143,8 +164,8 @@ html::fromgmi () { html::process_inline ;; '```'*) - is_plain=yes - echo '
'
+                language=$(cut -d'`' -f4 <<< "$line")
+                is_bare=yes
                 ;;
             '# '*)
                 html::make_heading "$line" 1 | html::process_inline
@@ -162,11 +183,7 @@ html::fromgmi () {
                 generate::make_link html "$line" | html::process_inline
                 ;;
             *)
-                if [[ "$is_plain" == no ]]; then
-                    html::make_paragraph "$line" | html::process_inline
-                else
-                    html::make_paragraph "$line"
-                fi
+                html::make_paragraph "$line" | html::process_inline
                 ;;
         esac
     done
@@ -212,6 +229,31 @@ html::test::default () {
     line='=> http://example.org/image.png Image description'
     assert::equals "$(generate::make_link html "$line")" \
         "Image description
" + + local input_block='``` +this + is + a + bare block +```' + + local output_block='
+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. @@ -237,7 +279,6 @@ html::test::exact () { 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
" } -- cgit v1.2.3 From 34d37a0b34da1f43af95cff014afd1522a578561 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 9 Apr 2023 13:49:07 +0300 Subject: add gemtexter version to footer --- lib/generate.source.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/generate.source.sh b/lib/generate.source.sh index 51da3ce..f56f22d 100644 --- a/lib/generate.source.sh +++ b/lib/generate.source.sh @@ -108,6 +108,7 @@ generate::_to_output_format () { fi $SED -i "s|%%TITLE%%|$title|g; s|%%DOMAIN%%|$DOMAIN|g; + s|%%GEMTEXTER%%|$GEMTEXTER|g; s|%%STYLESHEET%%|$stylesheet|g; s|%%STYLESHEET_OVERRIDE%%|$stylesheet_override|g;" "$dest.tmp" -- cgit v1.2.3 From e0e39d56a5edc124a1f3dfe37ac5043e05e85619 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 7 May 2023 11:47:47 +0300 Subject: dont make gemtexter stop when there isnt anything new to be committed to git --- lib/git.source.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/git.source.sh b/lib/git.source.sh index 8048aad..c2b216a 100644 --- a/lib/git.source.sh +++ b/lib/git.source.sh @@ -30,7 +30,9 @@ git::_add_all () { done local -r format="$(basename "$content_dir")" - git commit -a -m "$message for $format" + if ! git commit -a -m "$message for $format"; then + log INFO 'Nothing new to be added' + fi cd "$pwd" } -- cgit v1.2.3 From b9a748dafccc7f28aa695d3590be952560eedb35 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 8 May 2023 00:47:13 +0300 Subject: also escape ' properly --- lib/atomfeed.source.sh | 2 +- lib/html.source.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/atomfeed.source.sh b/lib/atomfeed.source.sh index cc810d1..079c2fb 100644 --- a/lib/atomfeed.source.sh +++ b/lib/atomfeed.source.sh @@ -74,7 +74,7 @@ ATOMHEADER while read -r gmi_file; do atomfeed::_entry "$gemfeed_dir" "$gmi_file" "$atom_file.tmp" - done < <(gemfeed::get_posts | head -n $ATOM_MAX_ENTRIES) + done < <(gemfeed::get_posts | head -n "$ATOM_MAX_ENTRIES") cat <> "$atom_file.tmp" diff --git a/lib/html.source.sh b/lib/html.source.sh index 7056f24..8f057a0 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -4,6 +4,7 @@ html::encode () { s|\&|\&|g; s|<|\<|g; s|>|\>|g; + s|'\''|\'|g; ' <<< "$@" } @@ -70,7 +71,7 @@ html::make_link () { descr="$link" fi - echo "$descr
" + echo "$descr
" } html::process_inline () { -- cgit v1.2.3 From 92b8b8721700cd47d7fef2ba64f166f45c797ca2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 8 May 2023 01:00:53 +0300 Subject: test the proper encoding of ' as well --- lib/html.source.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/html.source.sh b/lib/html.source.sh index 8f057a0..b60ac75 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -71,7 +71,7 @@ html::make_link () { descr="$link" fi - echo "$descr
" + echo "$descr
" } html::process_inline () { @@ -215,6 +215,10 @@ html::test::default () { assert::equals "$(generate::make_link html "$line")" \ "https://example.org
" + line="=> https://example.org/foo'bar" + assert::equals "$(generate::make_link html "$line")" \ + "https://example.org/foo'bar
" + line='=> index.html' assert::equals "$(generate::make_link html "$line")" \ "index.html
" -- cgit v1.2.3 From 49c1436c37a015d8e47cdc1c29f120cb42d0eb17 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 15 Jul 2023 14:04:54 +0300 Subject: Mastadon verification support --- lib/html.source.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/html.source.sh b/lib/html.source.sh index b60ac75..371866a 100644 --- a/lib/html.source.sh +++ b/lib/html.source.sh @@ -71,7 +71,12 @@ html::make_link () { descr="$link" fi - echo "$descr
" + local mastadon_verify='' + if [[ "$link" = "$MASTADON_URI" ]]; then + mastadon_verify=" rel='me'" + fi + + echo "$descr
" } html::process_inline () { @@ -192,6 +197,8 @@ $line" # Test default HTML variant. html::test::default () { + MASTADON_URI='' + local line='Hello world! This is a paragraph.' assert::equals "$(html::make_paragraph "$line")" '

Hello world! This is a paragraph.

' @@ -227,6 +234,13 @@ html::test::default () { assert::equals "$(generate::make_link html "$line")" \ "Description of the link
" + # Test Mastadon verification. + MASTADON_URI='https://fosstodon.org/@snonux' + line='=> https://fosstodon.org/@snonux Me at Mastadon' + assert::equals "$(generate::make_link html "$line")" \ + "Me at Mastadon
" + MASTADON_URI='' + line='=> http://example.org/image.png' assert::equals "$(generate::make_link html "$line")" \ "
" @@ -235,6 +249,7 @@ html::test::default () { assert::equals "$(generate::make_link html "$line")" \ "Image description
" + local input_block='``` this is -- cgit v1.2.3