From: Paul Hänsch Date: Fri, 18 Feb 2022 15:24:56 +0000 (+0100) Subject: macro processor plugin for markdown awk X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=034bc176a19e32f920b422604762f5ab6fd21bc7;p=shellwiki macro processor plugin for markdown awk --- diff --git a/md_macros.awk b/md_macros.awk new file mode 100755 index 0000000..a1e6450 --- /dev/null +++ b/md_macros.awk @@ -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"; } +}