From 34460ca715b295cc73c3f2bba4156c7f072ce122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Sun, 25 Sep 2022 20:55:51 +0200 Subject: [PATCH] asciiman: improve command escaping --- tools/asciiman.awk | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/asciiman.awk b/tools/asciiman.awk index da32db8..6db5695 100644 --- a/tools/asciiman.awk +++ b/tools/asciiman.awk @@ -32,7 +32,7 @@ function expand(s, attr) { function escape(s) { gsub(/\\/, "\\\\", s) gsub(/-/, "\\-", s) - gsub(/[.]/, "\\.", s) + sub(/^[.']/, "\\\\\\&&", s) return s } @@ -80,9 +80,6 @@ function inline(line) { line = escape(expand(line)) - # Enable double-spacing after the end of a sentence. - gsub(/\\[.][[:space:]]+/, ".\n", s) - # Strip empty URL descriptions, otherwise useful for demarking the end. while (match(line, /[^[:space:]]+\[\]/)) { line = substr(line, 1, RSTART + RLENGTH - 3) \ @@ -118,6 +115,15 @@ function inline(line) { substr(line, RSTART + RLENGTH) } + # Enable double-spacing after the end of a sentence. + gsub(/[.][[:space:]]+/, ".\n", line) + gsub(/[!][[:space:]]+/, "!\n", line) + gsub(/[?][[:space:]]+/, "?\n", line) + + # Quote commands resulting from that, as well as from expand(). + gsub(/\n[.]/, "\n\\\\\\&.", line) + gsub(/\n[']/, "\n\\\\\\&'", line) + sub(/[[:space:]]+[+]$/, "\n.br", line) print line }