asciiman: improve command escaping

This commit is contained in:
Přemysl Eric Janouch 2022-09-25 20:55:51 +02:00
parent 9883caf849
commit 34460ca715
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -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
}