diff options
| Commit | 1e2669d5d70117d3ad1d7786ffec0a49ed6313da (patch) | |
|---|---|---|
| Author | 2024-07-21 15:46:34 +0300 | |
| Committer | 2024-07-21 15:46:34 +0300 | |
| Files | 0a6b79054c61165bda9fde6d7df9b4abe137af11 /single.awk | |
| csg-1e2669d5d70117d3ad1d7786ffec0a49ed6313da.tar csg-1e2669d5d70117d3ad1d7786ffec0a49ed6313da.tar.gz csg-1e2669d5d70117d3ad1d7786ffec0a49ed6313da.zip | ||
| Parent | c85b6408a067ced3ee4c047668d965f7ae64374c (diff) | |
(single) Clean up and minor documentation
1 files changed, 18 insertions, 17 deletions
| -rw-r--r-- | single.awk | 35 |
@@ -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("<h" RLENGTH ">" $0 "</h" RLENGTH ">") @@ -107,10 +109,9 @@ function println(line) { } # setex-style headers !prev_blankline && /^[[:blank:]]*(=|-)+[[:blank:]]*$/ { - sub(/^<p>/, "", prev) + sub(/^<p>/, "", prev) ## from paragraph logic hlevel = 1 + ($0 ~ /-/) print "<h" hlevel ">" prev "</h" hlevel ">" - 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("</ol>") else println("</ul>") @@ -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("__", "<strong>", "</strong>") - surround("_", "<em>", "</em>") + surround("__" , "<strong>", "</strong>") + surround("_" , "<em>" , "</em>") surround("\\*\\*", "<strong>", "</strong>") - surround("\\*", "<em>", "</em>") - surround("~~", "<s>", "</s>") - surround("~", "<sub>", "</sub>") - surround("\\^", "<sup>", "</sup>") - surround("``", "<code>", "</code>") - surround("`", "<code>", "</code>") + surround("\\*" , "<em>" , "</em>") + surround("~~" , "<s>" , "</s>") + surround("~" , "<sub>" , "</sub>") + surround("\\^" , "<sup>" , "</sup>") + surround("``" , "<code>" , "</code>") + surround("`" , "<code>" , "</code>") } @@ -230,6 +230,7 @@ function surround(brace, opening, closing) { END { print prev if (!blankline && lengthStack("bq-level") == 0) { print "</p>" } + ## Flush stacks while (lengthStack("bq-level") > 0) { print "</blockquote>" popStack("bq-level") |
