-
Notifications
You must be signed in to change notification settings - Fork 2
/
prepare_txt.awk
55 lines (47 loc) · 858 Bytes
/
prepare_txt.awk
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
# Wrap text through 'fmt', except certain lines.
# Wrap buffered lines.
function flush() {
if (to_wrap && to_wrap != "\n") {
fmt = "fmt";
print to_wrap | fmt;
close(fmt);
to_wrap = "\n";
}
}
BEGIN {
skip_blank_line = 0;
}
# Print list lines as-is.
/^ - / {
flush();
print;
next;
}
# Print reference link lines as-is.
/^[[a-z0-9\-]+\]:/ {
flush();
print;
next;
}
# Skip image lines, as well as any following blank line.
/^!\[/ {
skip_blank_line = 1;
next;
}
# Skip blank line if requested.
/^$/ && skip_blank_line == 1 {
skip_blank_line = 0;
next;
}
# Buffer most text lines.
{
skip_blank_line = 0;
if (to_wrap && to_wrap != "\n") {
to_wrap = to_wrap "\n";
}
to_wrap = to_wrap $0;
}
# Wrap any remaining lines at the end.
END {
flush();
}