-
Notifications
You must be signed in to change notification settings - Fork 28
/
make-docs.sh
executable file
·78 lines (62 loc) · 1.81 KB
/
make-docs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Literal markdown, by Mark K Cowan [email protected]
#
# Special lines are lines beginning with:
# : [dir] - enter directory [dir], relative to LMD file
# < [file] - read contents of [file] and tab-indent it into MD file
# | [shell_cmd] - execute [shell_cmd] and tab-indent outputs into MD file
# $ [shell_cmd] - execute [shell_cmd] and direct outputs to STDERR
#
# Special lines must not be indented, the first character on the line must be
# the special character.
set -euo pipefail
if [ "${1:---help}" == "--help" ]; then
printf -- "Syntax: make-docs.sh <docfile>.lmd\n\n"
printf -- "Write output to <docfile>.md\n\n"
false
fi
declare -r root="$(realpath "$(dirname "$1")")"
declare -r in="$(basename "$1")"
declare -r out="${in%.lmd}.md"
rm -f -- node_modules/bin/google-webfonts node_modules/gulp-google-webfonts
ln -srf index.js node_modules/.bin/google-webfonts
ln -srf . node_modules/gulp-google-webfonts
export PATH="$PATH:$PWD/node_modules/.bin"
cd "${root}"
function indent {
local line
while IFS='' read line; do
printf -- "\t%s\n" "${line}"
done
}
function enter_dir {
local -r dir="$1"
cd "${root}/${dir}"
}
function read_in {
local -r file="$1"
printf >&2 -- "Read '%s' from '%s'\n" "${file}" "${PWD}"
<"${file}" indent
}
function pipe_in {
local -ra args=( $@ )
printf >&2 -- "Pipe in"
printf >&2 -- " '%s'" "${args[@]}"
printf >&2 -- " from '%s'\n" "${PWD}"
"${args[@]}" | indent
}
function map_line {
local -r line="$1"
local -r first="${line:0:1}"
local -r rest="$(echo "${line:1}" | sed -e 's/^\s*//')"
case "${first}" in
":") enter_dir "${rest}";;
"<") read_in "${rest}";;
"|") pipe_in "${rest}";;
"$") >&2 eval "${rest}";;
*) printf -- "%s\n" "${line}";;
esac
}
while IFS='' read __line; do
map_line "${__line}"
done < "${in}" | sed -e 's/[[:space:]]\+$//g' > "${out}"