diff options
| author | Paul Buetow <paul@buetow.org> | 2023-04-06 23:19:54 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-04-07 01:10:34 +0300 |
| commit | 88be39ae445cf41adb1c0c79876be808afb20d6d (patch) | |
| tree | 665b652797373f8e0b74b95c09816b4a4b77192d /lib/html.source.sh | |
| parent | 71be2b24ea0b5a061044b7c2bd03e8f690b9d289 (diff) | |
add HTML exact variant
Diffstat (limited to 'lib/html.source.sh')
| -rw-r--r-- | lib/html.source.sh | 107 |
1 files changed, 73 insertions, 34 deletions
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 "<span>$(html::encode "$text")</span><br />" + else + echo '<br />' + fi + elif [ -n "$text" ]; then echo "<p>$(html::encode "$text")</p>" 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 "<h${level}>$(html::encode "$text")</h${level}>" + + if [ "$HTML_VARIANT_TO_USE" = exact ]; then + #echo "<span class=h${level}>$(html::encode "$text")</span><br />" + echo "<h${level} style='display: inline'>$(html::encode "$text")</h${level}><br />" + else + echo "<h${level}>$(html::encode "$text")</h${level}><br />" + fi } # Make a HTML quotation html::make_quote () { local -r quote="${1/> }" - echo "<p class=\"quote\"><i>$(html::encode "$quote")</i></p>" + if [ "$HTML_VARIANT_TO_USE" = exact ]; then + echo "<span class=quote>$(html::encode "$quote")</span><br />" + else + echo "<p class=quote><i>$(html::encode "$quote")</i></p>" + fi } # Make a HTML image @@ -35,12 +51,12 @@ html::make_img () { local descr="$1"; shift if [ -z "$descr" ]; then - echo -n "<a href=\"$link\"><img src=\"$link\" /></a>" + echo -n "<a href='$link'><img src='$link' /></a>" else - echo -n "<a href=\"$link\"><img alt=\"$descr\" title=\"$descr\" src=\"$link\" /></a>" + echo -n "<a href='$link'><img alt='$descr' title='$descr' src='$link' /></a>" fi - echo "<br />" + echo '<br />' } # Make a HTML hyperlink @@ -56,17 +72,11 @@ html::make_link () { descr="$link" fi - echo "<a class=\"textlink\" href=\"$link\">$descr</a><br />" -} - -# Make inline code! -html::process_inline_code () { - $SED -E 's|`([^`]+)`|<span class="inlinecode">\1</span>|g' + echo "<a class=textlink href='$link'>$descr</a><br />" } 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|`([^`]+)`|<span class=inlinecode>\1</span>|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 "</ul>" + if [ "$HTML_VARIANT_TO_USE" = exact ]; then + echo "</ul><br />" + else + echo "</ul>" + 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")" '<p>Hello world! This is a paragraph.</p>' @@ -165,39 +180,63 @@ html::test () { line='echo foo 2>&1' assert::equals "$(html::make_paragraph "$line")" '<p>echo foo 2>&1</p>' - line='# Header 1' - assert::equals "$(html::make_heading "$line" 1)" '<h1>Header 1</h1>' - - line='## Header 2' - assert::equals "$(html::make_heading "$line" 2)" '<h2>Header 2</h2>' - - line='### Header 3' - assert::equals "$(html::make_heading "$line" 3)" '<h3>Header 3</h3>' - line='> This is a quote' - assert::equals "$(html::make_quote "$line")" '<p class="quote"><i>This is a quote</i></p>' + assert::equals "$(html::make_quote "$line")" "<p class=quote><i>This is a quote</i></p>" line='Testing: `hello_world.sh --debug` :-) `another one`!' - assert::equals "$(echo "$line" | html::process_inline_code)" \ - 'Testing: <span class="inlinecode">hello_world.sh --debug</span> :-) <span class="inlinecode">another one</span>!' + assert::equals "$(echo "$line" | html::process_inline)" \ + "Testing: <span class=inlinecode>hello_world.sh --debug</span> :-) <span class=inlinecode>another one</span>!" line='=> https://example.org' assert::equals "$(generate::make_link html "$line")" \ - '<a class="textlink" href="https://example.org">https://example.org</a><br />' + "<a class=textlink href='https://example.org'>https://example.org</a><br />" line='=> index.html' assert::equals "$(generate::make_link html "$line")" \ - '<a class="textlink" href="index.html">index.html</a><br />' + "<a class=textlink href='index.html'>index.html</a><br />" line='=> http://example.org Description of the link' assert::equals "$(generate::make_link html "$line")" \ - '<a class="textlink" href="http://example.org">Description of the link</a><br />' + "<a class=textlink href='http://example.org'>Description of the link</a><br />" line='=> http://example.org/image.png' assert::equals "$(generate::make_link html "$line")" \ - '<a href="http://example.org/image.png"><img src="http://example.org/image.png" /></a><br />' + "<a href='http://example.org/image.png'><img src='http://example.org/image.png' /></a><br />" line='=> http://example.org/image.png Image description' assert::equals "$(generate::make_link html "$line")" \ - '<a href="http://example.org/image.png"><img alt="Image description" title="Image description" src="http://example.org/image.png" /></a><br />' + "<a href='http://example.org/image.png'><img alt='Image description' title='Image description' src='http://example.org/image.png' /></a><br />" +} + +# Test exact HTML variant. +html::test::exact () { + local line='Hello world! This is a paragraph.' + assert::equals "$(html::make_paragraph "$line")" "<span>Hello world! This is a paragraph.</span><br />" + + line='' + assert::equals "$(html::make_paragraph "$line")" '<br />' + + line='Foo &<>& Bar!' + assert::equals "$(html::make_paragraph "$line")" "<span>Foo &<>& Bar!</span><br />" + + line='echo foo 2>&1' + assert::equals "$(html::make_paragraph "$line")" "<span>echo foo 2>&1</span><br />" + + line='# Header 1' + assert::equals "$(html::make_heading "$line" 1)" "<h1 style='display: inline'>Header 1</h1><br />" + + line='## Header 2' + assert::equals "$(html::make_heading "$line" 2)" "<h2 style='display: inline'>Header 2</h2><br />" + + line='### Header 3' + assert::equals "$(html::make_heading "$line" 3)" "<h3 style='display: inline'>Header 3</h3><br />" + + + line='> This is a quote' + assert::equals "$(html::make_quote "$line")" "<span class=quote>This is a quote</span><br />" +} + +html::test () { + HTML_VARIANT_TO_USE=default html::test::default + HTML_VARIANT_TO_USE=exact html::test::exact } |
