aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-29 18:12:48 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-29 18:12:48 +0000
commit99e2817d51dfa45b59276e6d002c6dd95b9f4156 (patch)
tree5b3f99bbd5c68fd8968c19da9a4267ee0bcf050c
parenta08db38f245f68bf218f55f7a7a58defe27ca054 (diff)
downloadem-99e2817d51dfa45b59276e6d002c6dd95b9f4156.tar.gz
Fix multi-word inline formatting
-rwxr-xr-xem36
1 files changed, 20 insertions, 16 deletions
diff --git a/em b/em
index 1b45893..4977ef3 100755
--- a/em
+++ b/em
@@ -57,22 +57,26 @@ function format(line) {
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 " "
+ if (match(w[i], "^`"))
+ w[i] = "<tt>" substr(w[i], 2)
+ else if (match(w[i], "^\\*"))
+ w[i] = "<i>" substr(w[i], 2)
+ else if (match(w[i], "^_"))
+ w[i] = "<b>" substr(w[i], 2)
+ if (match(w[i], "`$"))
+ w[i] = substr(w[i], 1, RLENGTH-2) "</tt>"
+ else if (match(w[i], "\\*$"))
+ w[i] = substr(w[i], 1, RLENGTH-2) "</i>"
+ else if (match(w[i], "_$"))
+ w[i] = substr(w[i], 1, RLENGTH-2) "</b>"
+ else if (match(w[i], "`[.,:;?!]$"))
+ w[i] = substr(w[i], 1, RSTART-1) "</tt>" substr(w[i], RSTART+1)
+ else if (match(w[i], "\\*\.$"))
+ w[i] = substr(w[i], 1, RSTART-1) "</i>" substr(w[i], RSTART+1)
+ else if (match(w[i], "_[.,:;?!]$"))
+ w[i] = substr(w[i], 1, RSTART-1) "</b>" substr(w[i], RSTART+1)
+ printf "%s", w[i]
+ if (i < n) printf " "
}
printf "\n"
}