From 1e2669d5d70117d3ad1d7786ffec0a49ed6313da Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 21 Jul 2024 15:46:34 +0300 Subject: (single) Clean up and minor documentation --- single.awk | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'single.awk') diff --git a/single.awk b/single.awk index 82555f6..5922d35 100644 --- a/single.awk +++ b/single.awk @@ -30,7 +30,7 @@ # [x] Single line # [ ] Multi-line # [ ] Fenced code blocks ```lang ``` -# [ ] Table alignment +# [ ] Tables BEGIN { prev_blankline = blankline = 1 @@ -64,6 +64,7 @@ function println(line) { # Auto-escape & /&/ { ampstart = 0 + ## gsub(/&(?![[:alnum:]#]+;)/, "&") while (match(substr($0, ampstart + 1), /&/)) { ampstart += RSTART if (match(substr($0, ampstart), /&[[:alnum:]#]+;/)) { continue } @@ -98,6 +99,7 @@ function println(line) { /^[[:blank:]]*#+/ { match($0, /#+/) if (RLENGTH <= 6) { + ## Remove prefix/suffix gsub(/^[[:blank:]]*#+[[:blank:]]*/, "") gsub(/[[:blank:]]*#+[[:blank:]]*$/, "") println("" $0 "") @@ -107,10 +109,9 @@ function println(line) { } # setex-style headers !prev_blankline && /^[[:blank:]]*(=|-)+[[:blank:]]*$/ { - sub(/^

/, "", prev) + sub(/^

/, "", prev) ## from paragraph logic hlevel = 1 + ($0 ~ /-/) print "" prev "" - prev = "" blankline = 1 skipprint = 1 next @@ -138,9 +139,9 @@ function abs(x) { return ((x < 0) ? -x : x) } !blankline && lengthStack("list-level") > 0 { match($0, /^ */) indent = RLENGTH - # Compensating factor for list items match($0, /(\*|\+|-|[[:digit:]]+\.) /) if (RLENGTH == -1) RLENGTH = 0 + ## indent + RLENGTH = length(" * " or " 1. ") while (indent + RLENGTH < abs(topStack("list-level"))) { if (topStack("list-level") < 0) println("") else println("") @@ -176,13 +177,12 @@ blankline { # Links /\[[^\]]*\]\([^)]*\)/ { while (match($0, /\[[^\]]*\]\(/)) { - astart = RSTART - inner_anchor = substr($0, RSTART + 1, RLENGTH - 3) + astart = RSTART + RLENGTH - 1 ## astart = indexof("(") + inner_anchor = substr($0, RSTART + 1, RLENGTH - 3) ## ...[xxxxx](...)... - aend = astart + RLENGTH - 1 match(substr($0, astart), /\]\([^)]*)/) - aend += RLENGTH - 2 - href = substr($0, astart + RSTART + 1, RLENGTH - 3) + aend += RLENGTH - 2 ## astart = indexof(")") + href = substr($0, astart + RSTART + 1, RLENGTH - 3) ## ...[...](xxxxx)... title = "" if (match(href, /"[^"]*"[[:blank:]]*$/)) { @@ -202,15 +202,15 @@ function surround(brace, opening, closing) { } } { - surround("__", "", "") - surround("_", "", "") + surround("__" , "", "") + surround("_" , "" , "") surround("\\*\\*", "", "") - surround("\\*", "", "") - surround("~~", "", "") - surround("~", "", "") - surround("\\^", "", "") - surround("``", "", "") - surround("`", "", "") + surround("\\*" , "" , "") + surround("~~" , "" , "") + surround("~" , "" , "") + surround("\\^" , "" , "") + surround("``" , "" , "") + surround("`" , "" , "") } @@ -230,6 +230,7 @@ function surround(brace, opening, closing) { END { print prev if (!blankline && lengthStack("bq-level") == 0) { print "

" } + ## Flush stacks while (lengthStack("bq-level") > 0) { print "" popStack("bq-level") -- cgit v1.3.1-23-gd82d