summaryrefslogtreecommitdiff
path: root/gmi2html.sh
diff options
context:
space:
mode:
authorSteph Enders <steph@senders.io>2024-03-11 13:36:30 -0400
committerSteph Enders <steph@senders.io>2024-03-11 13:36:30 -0400
commita6c2523aed55f01ce8390272619cfee0db7cc3a5 (patch)
treefc7ba149cf186273ca7f6d0f8fc2507295ae63fb /gmi2html.sh
parenta781714767af8d02f8cdd663efe2d878a0d26735 (diff)
Fix trailing pre support and simplify close quote logicquote-attribution
Now if you have: > some quote \# heading or > some quote ``` pre ``` or > some quote * List * Items It won't add attribution. This requires hoisting the quote logic to the top; below the pre-print-line which must remain at the top! But this should make it so we get proper attributions now!
Diffstat (limited to 'gmi2html.sh')
-rwxr-xr-xgmi2html.sh66
1 files changed, 31 insertions, 35 deletions
diff --git a/gmi2html.sh b/gmi2html.sh
index 4f73526..f9ea89c 100755
--- a/gmi2html.sh
+++ b/gmi2html.sh
@@ -14,17 +14,36 @@ GMI=$1
list=0
pre=0
quote=0
-empty_line=0
while read line; do
- if [ -z "$line" ]; then
- empty_line=1
+ # if in pre-mode and not closing - print and skip
+ if [ $pre -eq 1 ]; then
+ if [ ! -n "$(sed -nE '/^[`]{3}/p' <<< $line)" ]; then
+ echo "$line"
+ continue;
+ fi
+ fi
+
+
+ # quotes
+ if [ -n "$(sed -nE '/^[>] .+/p' <<< $line)" ]; then
+ if [ $quote -eq 0 ]; then
+ echo "<figure><blockquote>"
+ fi
+ quote=1;
+ text=$(sed -E 's/^[>] (.+)$/\1/g' <<< $line)
+ echo "<p>$text</p>"
+ continue
else
- empty_line=0
+ if [ $quote -eq 1 ]; then
+ if [ -z "$(sed -E '/^[#`*]/d' <<< $line)" ]; then
+ echo "</blockquote></figure>"
+ quote=0
+ fi
+ fi
fi
-
- # pre formatted text
+
if [ -n "$(sed -nE '/^[`]{3}/p' <<< $line)" ]; then
if [ $pre -eq 0 ]; then
echo "<pre>"
@@ -35,11 +54,7 @@ while read line; do
fi
continue;
fi
- if [ $pre -eq 1 ]; then
- echo "$line"
- continue;
- fi
-
+
# lists
if [ -n "$(sed -nE '/^[*] .+/p' <<< "$line")" ]; then
if [ $list -eq 0 ]; then
@@ -55,26 +70,7 @@ while read line; do
fi
list=0;
fi
-
- # quotes
- if [ -n "$(sed -nE '/^[>] .+/p' <<< $line)" ]; then
- if [ $quote -eq 0 ]; then
- echo "<figure><blockquote>"
- fi
- quote=1;
- text=$(sed -E 's/^[>] (.+)$/\1/g' <<< $line)
- echo "<p>$text</p>"
- continue
- else
- if [ $quote -eq 1 ]; then
- if [ $empty_line -eq 1 ]; then
- echo "</blockquote></figure>"
- quote=0
- continue
- fi
- fi
- fi
-
+
# single line modifiers
if [ -n "$(sed -nE '/^# .+/p' <<< $line)" ]; then
text=$(sed -E 's/^# (.+)$/\1/g' <<< $line)
@@ -100,21 +96,21 @@ while read line; do
fi
if [ $quote -eq 1 ]; then
- echo "— <a href='${href}' rel='noopener' target='_blank'>$text</a>"
+ echo "<cite>— <a href='${href}' rel='noopener' target='_blank'>$text</a></cite>"
else
echo "<p><a href='${href}' rel='noopener' target='_blank'>$text</a></p>"
fi
continue
fi
-
+
# skip blank lines
- if [ $empty_line -eq 1 ]; then
+ if [ -z "$line" ]; then
continue
fi
# default paragraphs
if [ $quote -eq 1 ]; then
- echo "— $line"
+ echo "<cite>— $line</cite>"
else
echo "<p>$line</p>"
fi