From 1ed284b29de05ae8046734e818e2f0583b56a1e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 25 May 2023 13:19:44 +0200 Subject: [PATCH] split up markdown parser into modular rendering pipeline --- parsers/50_markdown.sh | 11 +++++++++++ parsers/60_translation_links.sh | 7 +++++++ tools.sh | 26 +++++++++++++------------- 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100755 parsers/50_markdown.sh create mode 100755 parsers/60_translation_links.sh 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 -- 2.39.2