summaryrefslogtreecommitdiff
path: root/src/snippets
blob: fde4df6e1993103e5c16e8b246313862e06c5b41 (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
#!/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
	}
	in_block = !in_block
	next
}

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