summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-04-06 23:19:54 +0300
committerPaul Buetow <paul@buetow.org>2023-04-07 01:10:34 +0300
commit88be39ae445cf41adb1c0c79876be808afb20d6d (patch)
tree665b652797373f8e0b74b95c09816b4a4b77192d
parent71be2b24ea0b5a061044b7c2bd03e8f690b9d289 (diff)
add HTML exact variant
-rw-r--r--extras/html/style.css6
-rwxr-xr-xgemtexter6
-rw-r--r--gemtexter.conf3
-rw-r--r--lib/html.source.sh107
4 files changed, 84 insertions, 38 deletions
diff --git a/extras/html/style.css b/extras/html/style.css
index b3d6052..7639916 100644
--- a/extras/html/style.css
+++ b/extras/html/style.css
@@ -46,16 +46,16 @@ a.textlink:before {
padding-left: 11px;
}
-p.quote {
+.quote {
font-style: italic;
}
-p.quote:before {
+.quote:before {
content: "« ";
padding-left: 2px;
}
-p.quote:after {
+.quote:after {
content: " »";
padding-right: 2px;
}
diff --git a/gemtexter b/gemtexter
index 119d4fa..8a4d43f 100755
--- a/gemtexter
+++ b/gemtexter
@@ -37,6 +37,12 @@ else
source ./gemtexter.conf
fi
+if [[ -z "$HTML_VARIANT" ]]; then
+ export HTML_VARIANT_TO_USE=default
+else
+ export HTML_VARIANT_TO_USE="$HTML_VARIANT"
+fi
+
source ./lib/assert.source.sh
source ./lib/atomfeed.source.sh
source ./lib/gemfeed.source.sh
diff --git a/gemtexter.conf b/gemtexter.conf
index 5095d22..b5f03be 100644
--- a/gemtexter.conf
+++ b/gemtexter.conf
@@ -9,8 +9,9 @@ declare -xr PRE_GENERATE_HOOK=./pre_generate_hook.sh
declare -xr POST_PUBLISH_HOOK=./post_publish_hook.sh
declare -xr HTML_HEADER=./extras/html/header.html.part
declare -xr HTML_FOOTER=./extras/html/footer.html.part
-declare -xr HTML_CSS_STYLE=./extras/html/style.css
declare -xr HTML_WEBFONT_TEXT=./extras/html/hack/Hack-Regular.ttf
declare -xr HTML_WEBFONT_CODE=./extras/html/hack/Hack-Regular.ttf
declare -xr HTML_WEBFONT_HANDNOTES=./extras/html/khand/khand.ttf
declare -xr HTML_WEBFONT_TYPEWRITER=./extras/html/zai-aeg-mignon-typewriter-1924/zai_AEGMignonTypewriter1924.ttf
+declare -xr HTML_VARIANT=exact
+declare -xr HTML_CSS_STYLE=./extras/html/style.css
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&gt;&amp;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 &amp;&lt;&gt;&amp; Bar!</span><br />"
+
+ line='echo foo 2>&1'
+ assert::equals "$(html::make_paragraph "$line")" "<span>echo foo 2&gt;&amp;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
}