From ac0d28c9ecb163ab3cfbb32daf339782b0be7ab8 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 28 May 2020 08:37:06 -0500 Subject: Change typesetting --- bollux | 92 ++++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/bollux b/bollux index 6f8ea8b..a74db7d 100755 --- a/bollux +++ b/bollux @@ -317,8 +317,8 @@ display() { log d "typeset_$submime" { normalize_crlf | - run "typeset_$submime" | tee "$BOLLUX_PAGESRC" | + run "typeset_$submime" | run "${less_cmd[@]}" } || run handle_keypress "$?" else @@ -351,28 +351,66 @@ normalize_crlf() { typeset_gemini() { gawk ' - BEGIN { pre = 0 } - /^###/ { sub(/^#+[[:space:]]*/, ""); - printf "### \033[3m%s\033[0m\n", $0 - next } - /^##/ { sub(/^#+[[:space:]]*/, ""); - printf "## \033[1m%s\033[0m\n", $0 - next } - /^#/ { sub(/^#+[[:space:]]*/, ""); - printf "# \033[1;4m%s\033[0m\n", $0 - next } - /^=>/ { - sub(/=>[[:space:]]*/, "") - url = $1; desc = "" - for (w=2;w<=NF;w++) - desc = desc (desc?" ":"") $w - printf "=> \033[1m[%02d]\033[0m \033[4m%s\033[0m\t\033[36m%s\033[0m\n", - (++ln), desc, url - next } - /```/ { pre = !pre; next } - pre { printf "``` %s\n", $0; next } - # /^\*/ { sub(/\*[[:space:]]*/, ""); } - { sub(/^/, " "); print } + BEGIN { + pre = 0 + margin = margin ? margin : 4 + txs = "" + lns = "\033[1m" + lus = "\033[36m" + lts = "\033[4m" + pfs = "" + h1s = "\033[1;4m" + h2s = "\033[1m" + h3s = "\033[3m" + lis = "" + res = "\033[0m" + ms = "\033[35m" + } + /```/ { + pre = ! pre + next + } + pre { + mark = "```" + fmt = pfs "%s" res + text = $0 + } + /^#/ { + match($0, /#+/) + mark = substr($0, RSTART, RLENGTH) + sub(/#+[[:space:]]*/, "", $0) + level = length(mark) + if (level == 1) { + fmt = h1s "%s" res + } else if (level == 2) { + fmt = h2s "%s" res + } else { + fmt = h3s "%s" res + } + } + /^=>/ { + mark = "=>" + sub(/=>[[:space:]]*/, "", $0) + desc = $1 + text = "" + for (w = 2; w <= NF; w++) { + text = text (text ? " " : "") $w + } + fmt = lns "[" (++ln) "]" res " " lts "%s" res "\t" lus "%s" res + } + /^\*[[:space:]]/ { + mark = "*" + sub(/\*[[:space:]]*/, "", $0) + fmt = lis "%s" res + } + { + mark = mark ? mark : mark + fmt = fmt ? fmt : "%s" + text = text ? text : $0 + desc = desc ? desc : "" + printf ms "%" (margin-1) "s " res fmt "\n", mark, text, desc + mark = fmt = text = desc = "" + } ' } @@ -407,11 +445,11 @@ select_url() { } extract_links() { - gawk -F$'\t' '/^=>/ { - gsub("\033\\[[^m]*m", "") - sub(/=>[[:space:]]*\[[0-9]+\][[:space:]]*/,"") + gawk -F$'\t' ' + /^=>/ { + sub(/=>[[:space:]]*/,"") if ($2) - printf "%s (\033[34m%s\033[0m)\n", $2, $1 + printf "%s (\033[34m%s\033[0m)\n", $1, $2 else printf "%s\n", $1 }' -- cgit 1.4.1-21-gabe81