summaryrefslogtreecommitdiff
path: root/src/snippets
blob: be312746005c9c8d98fff671b9fee606c04c3d6b (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
#!/bin/sh
set -euo pipefail


usage() {
	echo 'Usage: snippets FILENAME.adoc'
}

FILENAME="${1:-}"
eval "$(assert-arg -- "$FILENAME" 'FILENAME.adoc')"


awk -v BASE="${FILENAME%.adoc}.html" '
/^----$/ {
	if (!in_block) {
		file = BASE "." count++ ".txt"
		print file
		system("rm -f " file )
	}
	in_block = !in_block
	next
}

in_block {
	print >> file
}
' "$FILENAME"