From a6c2523aed55f01ce8390272619cfee0db7cc3a5 Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Mon, 11 Mar 2024 13:36:30 -0400 Subject: Fix trailing pre support and simplify close quote logic 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! --- gmi2html.sh | 66 +++++++++++++++++++++++++++++-------------------------------- 1 file 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 "
" + fi + quote=1; + text=$(sed -E 's/^[>] (.+)$/\1/g' <<< $line) + echo "

$text

" + continue else - empty_line=0 + if [ $quote -eq 1 ]; then + if [ -z "$(sed -E '/^[#`*]/d' <<< $line)" ]; then + echo "
" + quote=0 + fi + fi fi - - # pre formatted text + if [ -n "$(sed -nE '/^[`]{3}/p' <<< $line)" ]; then if [ $pre -eq 0 ]; then echo "
"
@@ -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 "
" - fi - quote=1; - text=$(sed -E 's/^[>] (.+)$/\1/g' <<< $line) - echo "

$text

" - continue - else - if [ $quote -eq 1 ]; then - if [ $empty_line -eq 1 ]; then - echo "
" - 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 "— $text" + echo "$text" else echo "

$text

" 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 "— $line" else echo "

$line

" fi -- cgit v1.2.3-54-g00ecf