diff options
Diffstat (limited to 'gmi2html.sh')
-rwxr-xr-x | gmi2html.sh | 66 |
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 |