aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"
}