blob: 468b3aa8cca50cc7ca44ae46befac5c505f7e642 (
plain) (
blame)
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
|
#!/bin/sh
set -euo pipefail
usage() {
echo 'Usage: adoc [-x] [-s] [-n INDENT_LEN] FILENAME.adoc'
}
EXTRACT_CODE=false
STANDALONE=false
INDENT_LEN=0
while getopts 'xsn:' flag; do
case "$flag" in
(x)
EXTRACT_CODE=true
;;
(s)
STANDALONE=true
;;
(n)
INDENT_LEN="$OPTARG"
;;
(*)
usage >&2
exit 2
;;
esac
done
shift $((OPTIND - 1))
FILENAME="${1:-}"
eval "$(assert-arg -- "$FILENAME" 'FILENAME.adoc')"
plaintext_links() {
awk -v BASE="$(basename "$FILENAME" .adoc)".html '
{ print }
/^----$/ {
in_block = !in_block
if (in_block) {
next
}
file = BASE "." count++ ".txt"
print "[role=plaintext]"
print "link:" file "[plaintext]"
}'
}
fix_header_anchor_position() {
sed 's|^\(<h2 .*\)\(<a .*</a>\)\(.*\)\(</h2>\)$|\1\3\2\4|'
}
runtidy() {
statusconv 1:0 tidy \
-quiet \
-indent \
--indent-attributes yes \
--show-body-only yes \
--show-warnings no \
--tidy-mark no \
--wrap 120
}
indent_4_blocks() {
printf '<div><div><div><div>%s</div></div></div></div>' "$(cat -)" |
runtidy |
head -n -4 |
tail -n +5
}
cat "$FILENAME" |
plaintext_links |
asciidoctor -s - |
fix_header_anchor_position |
indent_4_blocks
|