3 margin = margin ? margin : 4
6 lns = "\033[1m" # link number style
7 lus = "\033[36m" # link url style
8 lts = "\033[4m" # link text style
9 pfs = "" # preformatted style
11 h1s = "\033[1;4m" # h1 style
12 h2s = "\033[1m" # h2 style
13 h3s = "\033[3m" # h3 style
14 lis = "" # list item style
16 res = "\033[0m" # reset style
29 mark = substr($0, RSTART, RLENGTH)
30 sub(/#+[[:space:]]*/, "", $0)
34 } else if (level == 2) {
42 sub(/=>[[:space:]]*/, "", $0)
45 for (w = 2; w <= NF; w++) {
46 text = text (text ? " " : "") $w
48 fmt = lns "[" (++ln) "]" res " " lts "%s" res "\t" lus "%s" res
52 sub(/\*[[:space:]]*/, "", $0)
56 mark = mark ? mark : mark
57 fmt = fmt ? fmt : "%s"
58 text = text ? text : fold($0, " ")
59 desc = desc ? desc : ""
60 printf "%-" margin "s" fmt "\n", mark, text, desc
61 mark = fmt = text = desc = ""
63 function fold(str, sep, cols, out, cmd, i, j, len, chars, c, last, f, first)
66 # checks if stdout is a tty
67 if (system("test -t 1")) {
75 # squeeze tabs and newlines to spaces
76 gsub(/[\t\n]/, " ", str)
77 # if "sep" is empty, just fold on cols with substr
80 out = substr(str, 1, cols)
81 for (i = cols + 1; i <= len; i += cols) {
83 for (j = 1; j < margin; j++) {
86 out = out substr(str, i, cols)
89 # otherwise, we have to loop over every character (can't split() on sep, it
90 # would destroy the existing separators)
92 # split string into char array
93 len = split(str, chars, "")
94 # set boolean, used to assign the first line differently
96 for (i = 1; i <= len; i += last) {
98 for (c = i + cols - 1; c >= i; c--) {
99 if (index(sep, chars[c])) {
109 out = substr(str, i, last)
113 for (j = 0; j < margin; j++) {
116 out = out substr(str, i, cols)