summaryrefslogtreecommitdiff
path: root/lib/html.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-06-13 07:24:50 +0100
committerPaul Buetow <paul@buetow.org>2022-06-13 07:24:50 +0100
commit7ff81723feeffd7def66808ba88978318f70343f (patch)
treed4b262a4479a2f74104b8bbe2961ae8fd8fde612 /lib/html.source.sh
parent88cc961dfce2985e4631587a4d503c45abafd235 (diff)
add inline code support to HTML
Diffstat (limited to 'lib/html.source.sh')
-rw-r--r--lib/html.source.sh35
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/html.source.sh b/lib/html.source.sh
index fe4c86e..1a35d75 100644
--- a/lib/html.source.sh
+++ b/lib/html.source.sh
@@ -59,6 +59,16 @@ html::make_link () {
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'
+}
+
+html::process_inline () {
+ # As of now we only inlinde "code blocks", but we can chain more here later!
+ html::process_inline_code
+}
+
# Convert Gemtext to HTML
html::fromgmi () {
local is_list=no
@@ -88,29 +98,34 @@ html::fromgmi () {
'* '*)
is_list=yes
echo "<ul>"
- echo "<li>$(html::encode "${line/\* /}")</li>"
+ echo "<li>$(html::encode "${line/\* /}")</li>" |
+ html::process_inline
;;
'```'*)
is_plain=yes
- echo "<pre>"
+ echo '<pre>'
;;
'# '*)
- html::make_heading "$line" 1
+ html::make_heading "$line" 1 | html::process_inline
;;
'## '*)
- html::make_heading "$line" 2
+ html::make_heading "$line" 2 | html::process_inline
;;
'### '*)
- html::make_heading "$line" 3
+ html::make_heading "$line" 3 | html::process_inline
;;
'> '*)
- html::make_quote "$line"
+ html::make_quote "$line" | html::process_inline
;;
'=> '*)
- generate::make_link html "$line"
+ generate::make_link html "$line" | html::process_inline
;;
*)
- html::make_paragraph "$line"
+ if [[ "$is_plain" == no ]]; then
+ html::make_paragraph "$line" | html::process_inline
+ else
+ html::make_paragraph "$line"
+ fi
;;
esac
done
@@ -142,6 +157,10 @@ html::test () {
line='> This is a quote'
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>!'
+
line='=> https://example.org'
assert::equals "$(generate::make_link html "$line")" \
'<a class="textlink" href="https://example.org">https://example.org</a><br />'