aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-30 15:01:14 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-30 15:01:14 +0200
commit089593bb0fbe72ef0d66c5efb1167a6c0d14b701 (patch)
treeee7d1baab0ff4fe2e54cbf6f5871c77a2a928436
parent035bfe5e81b80ef9df03414c7c567093ce26629a (diff)
downloadliberty-089593bb0fbe72ef0d66c5efb1167a6c0d14b701.tar.gz
liberty-089593bb0fbe72ef0d66c5efb1167a6c0d14b701.tar.xz
liberty-089593bb0fbe72ef0d66c5efb1167a6c0d14b701.zip
asciiman: render libertyxdr.adoc properly
-rw-r--r--tools/asciiman.awk57
1 files 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)