Last active
January 27, 2024 01:43
-
-
Save EvanEdwards/a65ea29f2d86fbef9341d15e0c05399a to your computer and use it in GitHub Desktop.
Convert pandoc template to handlebars (partial)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -lt 1 ] || [ "$1" == "--help" ] || [ "$1" == "-h" ] | |
then | |
echo "pandoc2handlebars.sh FILE [FILE...] | |
Converts (partially) the given Pandoc templates to Handlebars files. | |
Hand edit the \$for(var)\$ and other unconverted bits. | |
" | |
exit 1 | |
fi | |
for FN in "$@" | |
do | |
# Verify or skip | |
[ -f "$FN" ] || echo "WARNING: '$FN' is not a file. (skipping)" 1>&2 | |
[ -f "$FN" ] || continue | |
[ -f "${FN}.handlebars" ] && echo "WARNING: Refusing to overwrite '${FN}.handlebars' (skipping)" 1>&2 | |
[ -f "${FN}.handlebars" ] && continue | |
sed -E 's/\$endif\$/{{\/if}}/g;s/\$if\(([^\)]*)\)\$/{{#if \1}}/g;s/\$([A-Za-z][A-Za-z0-9.]*)\$/{{\1}}/g' <"$FN" >"${FN}.handebars" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This handles a good chunk of the simple textual conversion, but doesn't convert
$for(var)$
because Handlebars uses{{this}}
, while Pandoc usesvar.property
. I didn't need to mass convert, so I just used this and hand edited the remainder.Might could use some whitespace handling, but I have never seen whitespace in
$pandoc.vars$
and am not even sure they are valid. This is a practical sed quickie.