Browse Source

fix up edges to what markdeep expects...

main
John-Mark Gurney 5 years ago
parent
commit
dcfc594f38
1 changed files with 44 additions and 1 deletions
  1. +44
    -1
      box.sh

+ 44
- 1
box.sh View File

@@ -13,16 +13,59 @@ function printtop () {
printf("%s\n", blank)
}

function printline(a)
{
printf("* %s%*s *\n", a, maxlength - length(a), "")
}

# return the string a, with the character at pos, replaced with chr
function replace(a, pos, chr)
{
return substr(a, 1, pos - 1) chr substr(a, pos + 1)
}

output == 1 && FNR == 1 {
printtop()
printf("* %*s *\n", maxlength, "")

prevline = $0
next
}

output == 1 {
printf("* %s%*s *\n", $0, maxlength - length, "")
# fix up horizontal issues
gsub("\\|-", "+-", prevline)
gsub("\\| -", "+--", prevline)
gsub("-\\|", "-+", prevline)
gsub("- \\|", "--+", prevline)

# Fix up vertical issues

# first fix edges from below
r = split($0, a, "|")
pos = 0
for (i = 2; i <= r; i++) {
pos += length(a[i - 1]) + 1
if (substr(prevline, pos, 1) == "-")
prevline = replace(prevline, pos, "+")
}

# fix edges from above
r = split(prevline, a, "|")
pos = 0
for (i = 2; i <= r; i++) {
pos += length(a[i - 1]) + 1
if (substr($0, pos, 1) == "-")
$0 = replace($0, pos, "+")
}

printline(prevline)

prevline = $0
}

END {
printline(prevline)
printf("* %*s *\n", maxlength, "")
printtop()
}


Loading…
Cancel
Save