Debian Codegraph @

scripts/fix-readmes.awk

raw
1 # Fix up readmes:
2 # * Replace ## with # in code blocks.
3 # * Remove [] without a following () from output.
4
5 BEGIN {
6 true = 1
7 false = 0
8 in_block = false
9 }
10
11 {
12 if (!in_block && $0 ~ /^```/) {
13 in_block = true
14 } else if (in_block && $0 ~ /^```$/) {
15 in_block = false
16 }
17
18 if (in_block) {
19 sub(/## /, "# ")
20 print $0
21 } else {
22 # Strip [] without a () that immediately follows them from
23 # the output.
24 subbed = gensub(/\[([^\[]+)]([^\(]|$)/, "\\1\\2", "g")
25 print subbed
26 }
27 }