From a08db38f245f68bf218f55f7a7a58defe27ca054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 29 Jan 2021 18:00:56 +0000 Subject: Add inline formatting This is arguably the ugliest part of the implementation, but that's because awk isn't built for inline text processing. --- em | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/em b/em index 13beb29..1b45893 100755 --- a/em +++ b/em @@ -52,6 +52,31 @@ function term(line, t) { # t is a local variable printf "
%s
", t } +function format(line) { + n = split(line, w, "[ ]") + for (i = 0; i <= n; i++) { + if (w[i] == "") + continue; + if (match(w[i], "^`.+`$")) + printf "%s", substr(w[i], 2, RLENGTH-2) + else if (match(w[i], "^\\*.+\\*$")) + printf "%s", substr(w[i], 2, RLENGTH-2) + else if (match(w[i], "^_.+_$")) + printf "%s", substr(w[i], 2, RLENGTH-2) + else if (match(w[i], "^`.+`[.,:;?!]$")) + printf "%s%s", substr(w[i], 2, RLENGTH-3), substr(w[i], RLENGTH) + else if (match(w[i], "^\\*.+\\*[.,:;?!]$")) + printf "%s%s", substr(w[i], 2, RLENGTH-3), substr(w[i], RLENGTH) + else if (match(w[i], "^_.+_[.,:;?!]$")) + printf "%s%s", substr(w[i], 2, RLENGTH-3), substr(w[i], RLENGTH) + else + printf "%s", w[i] + if (i < n) + printf " " + } + printf "\n" +} + BEGIN { expectblock = 1; itemlevel = 1 } END { breakblock() } @@ -85,4 +110,4 @@ block = "ol" && /^ [0-9]+\./ { item(5, "ol", line) } block = "ul" && /^ -/ { item(6, "ul", line) } block = "ol" && /^ [0-9]+\./ { item(6, "ol", line) } -{ print $0 } +{ format($0) } -- cgit v1.2.3