]> git.plutz.net Git - shellwiki/commitdiff
macro processor plugin for markdown awk
authorPaul Hänsch <paul@plutz.net>
Fri, 18 Feb 2022 15:24:56 +0000 (16:24 +0100)
committerPaul Hänsch <paul@plutz.net>
Fri, 18 Feb 2022 15:24:56 +0000 (16:24 +0100)
md_macros.awk [new file with mode: 0755]

diff --git a/md_macros.awk b/md_macros.awk
new file mode 100755 (executable)
index 0000000..a1e6450
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/awk -f
+#!/opt/busybox/awk -f
+
+function macro(call, LOCAL, line, files, n, exec) {
+  "cd " ENVIRON["MD_MACROS"] "; printf '%s/' *" |getline line;
+  split(line, files, "/");
+  for (n in files) { files[files[n]] = ""; delete files[n]; }
+  delete files[""];
+
+  split(call, exec);
+
+  if (exec[1] in files) {
+    RS=""; ORS=""; line="";
+    # TODO: proper shell-exec function with argument array
+    "printf '%s' " line " | " ENVIRON["MD_MACROS"] "/" call | getline line;
+    return line;
+  } else {
+    return HTML("<<" call ">>");
+  }
+}
+
+BEGIN {
+  if (ENVIRON["MD_MACROS"]) { AllowMacros = "true"; }
+}