From: Paul Hänsch Date: Thu, 25 May 2023 11:19:44 +0000 (+0200) Subject: split up markdown parser into modular rendering pipeline X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=1ed284b29de05ae8046734e818e2f0583b56a1e8;p=shellwiki split up markdown parser into modular rendering pipeline --- diff --git a/parsers/50_markdown.sh b/parsers/50_markdown.sh new file mode 100755 index 0000000..94a0b06 --- /dev/null +++ b/parsers/50_markdown.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +if which awk >/dev/null; then + awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" + # | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g' +elif which busybox >/dev/null; then + busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" + # | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g' +else + cat +fi diff --git a/parsers/60_translation_links.sh b/parsers/60_translation_links.sh new file mode 100755 index 0000000..0020719 --- /dev/null +++ b/parsers/60_translation_links.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ "$LANGUAGE" != "$LANGUAGE_DEFAULT" ]; then + sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g' +else + cat +fi diff --git a/tools.sh b/tools.sh index 7069227..b714ec6 100755 --- a/tools.sh +++ b/tools.sh @@ -3,19 +3,19 @@ [ "$include_tools" ] && return 0 include_tools="$0" -if [ "$(which awk)" ]; then - md() { - awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" \ - | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g' - } -elif [ "$(which busybox)" ]; then - md() { - busybox awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk" \ - | sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g' - } -else - md() { cat; } -fi +md(){ + local parser + + if [ "$#" = 0 ]; then + md "${_EXEC}"/parsers/* + elif [ "$#" = 1 ]; then + "$1" + else + parser="$1" + shift 1 + "$parser" |md "$@" + fi +} mdfile(){ # Check if page exists, if possible fall