diff options
author | Case Duckworth | 2020-05-28 08:37:06 -0500 |
---|---|---|
committer | Case Duckworth | 2020-05-28 08:37:06 -0500 |
commit | ac0d28c9ecb163ab3cfbb32daf339782b0be7ab8 (patch) | |
tree | b1a77fbcd16a65497694045d498e843d5b7bb1aa | |
parent | Add Makefiles (diff) | |
download | bollux-ac0d28c9ecb163ab3cfbb32daf339782b0be7ab8.tar.gz bollux-ac0d28c9ecb163ab3cfbb32daf339782b0be7ab8.zip |
Change typesetting
-rwxr-xr-x | bollux | 92 |
1 files changed, 65 insertions, 27 deletions
diff --git a/bollux b/bollux index 6f8ea8b..a74db7d 100755 --- a/bollux +++ b/bollux | |||
@@ -317,8 +317,8 @@ display() { | |||
317 | log d "typeset_$submime" | 317 | log d "typeset_$submime" |
318 | { | 318 | { |
319 | normalize_crlf | | 319 | normalize_crlf | |
320 | run "typeset_$submime" | | ||
321 | tee "$BOLLUX_PAGESRC" | | 320 | tee "$BOLLUX_PAGESRC" | |
321 | run "typeset_$submime" | | ||
322 | run "${less_cmd[@]}" | 322 | run "${less_cmd[@]}" |
323 | } || run handle_keypress "$?" | 323 | } || run handle_keypress "$?" |
324 | else | 324 | else |
@@ -351,28 +351,66 @@ normalize_crlf() { | |||
351 | 351 | ||
352 | typeset_gemini() { | 352 | typeset_gemini() { |
353 | gawk ' | 353 | gawk ' |
354 | BEGIN { pre = 0 } | 354 | BEGIN { |
355 | /^###/ { sub(/^#+[[:space:]]*/, ""); | 355 | pre = 0 |
356 | printf "### \033[3m%s\033[0m\n", $0 | 356 | margin = margin ? margin : 4 |
357 | next } | 357 | txs = "" |
358 | /^##/ { sub(/^#+[[:space:]]*/, ""); | 358 | lns = "\033[1m" |
359 | printf "## \033[1m%s\033[0m\n", $0 | 359 | lus = "\033[36m" |
360 | next } | 360 | lts = "\033[4m" |
361 | /^#/ { sub(/^#+[[:space:]]*/, ""); | 361 | pfs = "" |
362 | printf "# \033[1;4m%s\033[0m\n", $0 | 362 | h1s = "\033[1;4m" |
363 | next } | 363 | h2s = "\033[1m" |
364 | /^=>/ { | 364 | h3s = "\033[3m" |
365 | sub(/=>[[:space:]]*/, "") | 365 | lis = "" |
366 | url = $1; desc = "" | 366 | res = "\033[0m" |
367 | for (w=2;w<=NF;w++) | 367 | ms = "\033[35m" |
368 | desc = desc (desc?" ":"") $w | 368 | } |
369 | printf "=> \033[1m[%02d]\033[0m \033[4m%s\033[0m\t\033[36m%s\033[0m\n", | 369 | /```/ { |
370 | (++ln), desc, url | 370 | pre = ! pre |
371 | next } | 371 | next |
372 | /```/ { pre = !pre; next } | 372 | } |
373 | pre { printf "``` %s\n", $0; next } | 373 | pre { |
374 | # /^\*/ { sub(/\*[[:space:]]*/, ""); } | 374 | mark = "```" |
375 | { sub(/^/, " "); print } | 375 | fmt = pfs "%s" res |
376 | text = $0 | ||
377 | } | ||
378 | /^#/ { | ||
379 | match($0, /#+/) | ||
380 | mark = substr($0, RSTART, RLENGTH) | ||
381 | sub(/#+[[:space:]]*/, "", $0) | ||
382 | level = length(mark) | ||
383 | if (level == 1) { | ||
384 | fmt = h1s "%s" res | ||
385 | } else if (level == 2) { | ||
386 | fmt = h2s "%s" res | ||
387 | } else { | ||
388 | fmt = h3s "%s" res | ||
389 | } | ||
390 | } | ||
391 | /^=>/ { | ||
392 | mark = "=>" | ||
393 | sub(/=>[[:space:]]*/, "", $0) | ||
394 | desc = $1 | ||
395 | text = "" | ||
396 | for (w = 2; w <= NF; w++) { | ||
397 | text = text (text ? " " : "") $w | ||
398 | } | ||
399 | fmt = lns "[" (++ln) "]" res " " lts "%s" res "\t" lus "%s" res | ||
400 | } | ||
401 | /^\*[[:space:]]/ { | ||
402 | mark = "*" | ||
403 | sub(/\*[[:space:]]*/, "", $0) | ||
404 | fmt = lis "%s" res | ||
405 | } | ||
406 | { | ||
407 | mark = mark ? mark : mark | ||
408 | fmt = fmt ? fmt : "%s" | ||
409 | text = text ? text : $0 | ||
410 | desc = desc ? desc : "" | ||
411 | printf ms "%" (margin-1) "s " res fmt "\n", mark, text, desc | ||
412 | mark = fmt = text = desc = "" | ||
413 | } | ||
376 | ' | 414 | ' |
377 | } | 415 | } |
378 | 416 | ||
@@ -407,11 +445,11 @@ select_url() { | |||
407 | } | 445 | } |
408 | 446 | ||
409 | extract_links() { | 447 | extract_links() { |
410 | gawk -F$'\t' '/^=>/ { | 448 | gawk -F$'\t' ' |
411 | gsub("\033\\[[^m]*m", "") | 449 | /^=>/ { |
412 | sub(/=>[[:space:]]*\[[0-9]+\][[:space:]]*/,"") | 450 | sub(/=>[[:space:]]*/,"") |
413 | if ($2) | 451 | if ($2) |
414 | printf "%s (\033[34m%s\033[0m)\n", $2, $1 | 452 | printf "%s (\033[34m%s\033[0m)\n", $1, $2 |
415 | else | 453 | else |
416 | printf "%s\n", $1 | 454 | printf "%s\n", $1 |
417 | }' | 455 | }' |