From 089593bb0fbe72ef0d66c5efb1167a6c0d14b701 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Fri, 30 Sep 2022 15:01:14 +0200 Subject: asciiman: render libertyxdr.adoc properly --- tools/asciiman.awk | 57 ++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/tools/asciiman.awk b/tools/asciiman.awk index 55330ad..ddb1093 100644 --- a/tools/asciiman.awk +++ b/tools/asciiman.awk @@ -72,13 +72,39 @@ NR == 1 { print ".nh" } +function format(line, v) { + # Pass-through, otherwise useful for hacks, is a bit of a lie here, + # and formatting doesn't fully respect word boundaries. + while (line) { + if (match(line, /^[+][+][+][^+]+[+][+][+]/)) { + v = v substr(line, RSTART + 3, RLENGTH - 6) + } else if (match(line, /^__[^_]+__/)) { + v = v "\\fI" substr(line, RSTART + 2, RLENGTH - 4) "\\fP" + } else if (match(line, /^[*][*][^*]+[*][*]/)) { + v = v "\\fB" substr(line, RSTART + 2, RLENGTH - 4) "\\fP" + } else if (match(line, /^_[^_]+_/) && + substr(line, RSTART + RLENGTH) !~ /^[[:alnum:]]/) { + v = v "\\fI" substr(line, RSTART + 1, RLENGTH - 2) "\\fP" + } else if (match(line, /^[*][^*]+[*]/) && + substr(line, RSTART + RLENGTH) !~ /^[[:alnum:]]/) { + v = v "\\fB" substr(line, RSTART + 1, RLENGTH - 2) "\\fP" + } else { + v = v substr(line, 1, 1) + line = substr(line, 2) + continue + } + line = substr(line, RSTART + RLENGTH) + } + return v +} + function inline(line) { if (!line) { print ".sp" return } - line = escape(expand(line)) + line = format(escape(expand(line))) # Strip empty URL descriptions, otherwise useful for demarking the end. while (match(line, /[^[:space:]]+\[\]/)) { @@ -86,35 +112,6 @@ function inline(line) { substr(line, RSTART + RLENGTH) } - # Pass-through, otherwise useful for hacks, is a lie here. - while (match(line, /[+][+][+][^+]+[+][+][+]/)) { - line = substr(line, 1, RSTART - 1) \ - substr(line, RSTART + 3, RLENGTH - 6) \ - substr(line, RSTART + RLENGTH) - } - - # Italic and bold formatting doesn't respect any word boundaries. - while (match(line, /__[^_]+__/)) { - line = substr(line, 1, RSTART - 1) \ - "\\fI" substr(line, RSTART + 2, RLENGTH - 4) "\\fP" \ - substr(line, RSTART + RLENGTH) - } - while (match(line, /_[^_]+_/)) { - line = substr(line, 1, RSTART - 1) \ - "\\fI" substr(line, RSTART + 1, RLENGTH - 2) "\\fP" \ - substr(line, RSTART + RLENGTH) - } - while (match(line, /[*][*][^*]+[*][*]/)) { - line = substr(line, 1, RSTART - 1) \ - "\\fB" substr(line, RSTART + 2, RLENGTH - 4) "\\fP" \ - substr(line, RSTART + RLENGTH) - } - while (match(line, /[*][^*]+[*]/)) { - line = substr(line, 1, RSTART - 1) \ - "\\fB" substr(line, RSTART + 1, RLENGTH - 2) "\\fP" \ - substr(line, RSTART + RLENGTH) - } - # Enable double-spacing after the end of a sentence. gsub(/[.][[:space:]]+/, ".\n", line) gsub(/[!][[:space:]]+/, "!\n", line) -- cgit v1.2.3-70-g09d2