diff options
author | John Ankarström <john@ankarstrom.se> | 2021-01-29 18:00:56 +0000 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-01-29 18:00:56 +0000 |
commit | a08db38f245f68bf218f55f7a7a58defe27ca054 (patch) | |
tree | 457a6506ee0406b895de176747ffb681d13b4b5a | |
parent | 59ce3d3afd41fca58eb776963e94af92daa22e83 (diff) | |
download | em-a08db38f245f68bf218f55f7a7a58defe27ca054.tar.gz |
Add inline formatting
This is arguably the ugliest part of the implementation,
but that's because awk isn't built for inline text processing.
-rwxr-xr-x | em | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -52,6 +52,31 @@ function term(line, t) { # t is a local variable printf "<dt>%s</dt><dd>", t } +function format(line) { + n = split(line, w, "[ ]") + for (i = 0; i <= n; i++) { + if (w[i] == "") + continue; + if (match(w[i], "^`.+`$")) + printf "<tt>%s</tt>", substr(w[i], 2, RLENGTH-2) + else if (match(w[i], "^\\*.+\\*$")) + printf "<i>%s</i>", substr(w[i], 2, RLENGTH-2) + else if (match(w[i], "^_.+_$")) + printf "<b>%s</b>", substr(w[i], 2, RLENGTH-2) + else if (match(w[i], "^`.+`[.,:;?!]$")) + printf "<tt>%s</tt>%s", substr(w[i], 2, RLENGTH-3), substr(w[i], RLENGTH) + else if (match(w[i], "^\\*.+\\*[.,:;?!]$")) + printf "<i>%s</i>%s", substr(w[i], 2, RLENGTH-3), substr(w[i], RLENGTH) + else if (match(w[i], "^_.+_[.,:;?!]$")) + printf "<b>%s</b>%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) } |