diff options
author | Loïc Hoguin <[email protected]> | 2018-06-11 12:38:07 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-06-11 12:38:07 +0200 |
commit | 976dfc5d92e3e23f356cb19f17ff51b22c75e634 (patch) | |
tree | 2589053dfc25bd6f38afdd9a06bdbbf63680464c /scripts | |
parent | 524777054be30c848c1883ffd15b245c29f73004 (diff) | |
download | asciideck-976dfc5d92e3e23f356cb19f17ff51b22c75e634.tar.gz asciideck-976dfc5d92e3e23f356cb19f17ff51b22c75e634.tar.bz2 asciideck-976dfc5d92e3e23f356cb19f17ff51b22c75e634.zip |
Add scripts/asciidoc ad-hoc replacement and HTML output
This allows me to build ninenines.eu using Asciideck and
while the results are not perfect yet things are looking
pretty, pretty good. Adding source-highlight support,
showing images and fixing a few minor issues should bring
me to the point where I can drop Asciidoc.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/asciidoc | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/scripts/asciidoc b/scripts/asciidoc new file mode 100755 index 0000000..9e0d196 --- /dev/null +++ b/scripts/asciidoc @@ -0,0 +1,95 @@ +#!/usr/bin/env sh + +set -e +#set -x + +TEMP=$(getopt -o 'a:b:d:hso:nv' -l 'attribute:,backend:,doctype:,help,no-header-footer,out-file:,section-numbers,safe,theme:,verbose,version' -n asciidoc -- "$@") + +if [ $? -ne 0 ]; then + exit 1 +fi + +eval set -- "$TEMP" +unset TEMP + +NO_HEADER_FOOTER=0 +OUT_DIR= +OUT_FILE= +SAFE=0 +VERBOSE=0 + +while true; do + case "$1" in + '-a'|'--attribute') + echo 'The option -a|--attribute is currently ignored.' >&2 + shift 2 ;; + '-b'|'--backend') + echo 'The option -b|--backend is currently ignored.' >&2 + shift 2 ;; + '-d'|'--doctype') + echo 'The option -d|--doctype is currently ignored.' >&2 + shift 2 ;; + '-h'|'--help') + echo 'TODO' + exit 0 ;; + '-s'|'--no-header-footer') + NO_HEADER_FOOTER=1 + shift ;; + '-o'|'--out-file') + OUT_DIR=`dirname $2` + OUT_FILE=`basename ${2%.*}` + shift 2 ;; + '-n'|'--section-numbers') + echo 'The option -n|--section-numbers is currently ignored.' >&2 + shift ;; + '--safe') + SAFE=1 + shift ;; + '--theme') + echo 'The option --theme is currently ignored.' >&2 + shift ;; + '-v'|'--verbose') + VERBOSE=1 + shift ;; + '--version') + echo 'Asciideck compatibility script' + exit 0 ;; + '--') + shift + break ;; + *) + echo 'Unexpected error:' $1 >&2 + exit 1 ;; + esac +done + +IN_FILE= + +case "$1" in + '') + echo 'No file name was provided. Use - for standard input.' >&2 + exit 1 ;; + '-') + PARSE_CALL="asciideck:parse_stdin()" ;; + *) + IN_FILE=$1 + PARSE_CALL="asciideck:parse_file(\"$IN_FILE\")" ;; +esac + +if [ $IN_FILE -a -z $OUT_FILE ]; then + OUT_DIR=`dirname $IN_FILE` + OUT_FILE=`basename ${IN_FILE%.*}` +fi + +if [ $OUT_FILE ]; then + TRANSLATE_OPTS="#{outdir => \"$OUT_DIR\", outfile => \"$OUT_FILE\"}" +else + TRANSLATE_OPTS="#{}" +fi + +<&0 erl +A0 -boot no_dot_erlang -noshell -pz `dirname $0`/../ebin -eval " \ + case asciideck:to_html($PARSE_CALL, $TRANSLATE_OPTS) of \ + ok -> ok; \ + Output -> io:format(\"~s~n\", [Output]) \ + end, \ + halt()" |