File: fix-readmes.awk

package info (click to toggle)
rust-datatest-stable 0.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 440 kB
  • sloc: awk: 19; sh: 5; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 559 bytes parent folder | download | duplicates (3)
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
# Fix up readmes:
# * Replace ## with # in code blocks.
# * Remove [] without a following () from output.

BEGIN {
    true = 1
    false = 0
    in_block = false
}

{
    if (!in_block && $0 ~ /^```/) {
        in_block = true
    } else if (in_block && $0 ~ /^```$/) {
        in_block = false
    }

    if (in_block) {
        sub(/## /, "# ")
        print $0
    } else {
        # Strip [] without a () that immediately follows them from
        # the output.
        subbed = gensub(/\[([^\[]+)]([^\(]|$)/, "\\1\\2", "g")
        print subbed
    }
}