]> git.plutz.net Git - shellwiki/commitdiff
split up markdown parser into modular rendering pipeline
authorPaul Hänsch <paul@plutz.net>
Thu, 25 May 2023 11:19:44 +0000 (13:19 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 25 May 2023 11:19:44 +0000 (13:19 +0200)
parsers/50_markdown.sh [new file with mode: 0755]
parsers/60_translation_links.sh [new file with mode: 0755]
tools.sh

diff --git a/parsers/50_markdown.sh b/parsers/50_markdown.sh
new file mode 100755 (executable)
index 0000000..94a0b06
--- /dev/null
@@ -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 (executable)
index 0000000..0020719
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ "$LANGUAGE" != "$LANGUAGE_DEFAULT" ]; then
+  sed -E 's;(<[^>]+ )href="((/[^"/]+|[^"/]+[^:/]|)/([^"/]+/)*)"([^>]*>);\1href="\2:'"${LANGUAGE}"'"\5;g'
+else
+  cat
+fi
index 7069227d960f71d32fc87cc01ebd2143be8e1d27..b714ec6efcc9c6a0d6b032ec60b46ab22179c2c2 100755 (executable)
--- 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