Summary Files Commits Branches @commit @diff @stats
path: root / single.awk
diff options
context:
space:
mode:
Commit77226b4f56a25cb9b791f93b0d9cea66f3b1ff46 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-12-31 10:21:24 +0200
Committer
 Syndamia <kamen@syndamia.com>
2024-12-31 10:21:24 +0200
Files5ee2ca99747f794c64090ea85f4edf7fba5e0d8c /single.awk
csg-77226b4f56a25cb9b791f93b0d9cea66f3b1ff46.tar
csg-77226b4f56a25cb9b791f93b0d9cea66f3b1ff46.tar.gz
csg-77226b4f56a25cb9b791f93b0d9cea66f3b1ff46.zip
Parent1a4e8a89d2a331913e653d439e16e4138cfaf6e9 (diff)
fix(single): Surround properly handles long chains of * or _
1 files changed, 16 insertions, 7 deletions
-rw-r--r--single.awk23
diff --git a/single.awk b/single.awk
index bf80054..2ac29cf 100644
--- a/single.awk
+++ b/single.awk
@@ -299,20 +299,29 @@ blankline {
}
# Emphasis
-function surround(brace, opening, closing) {
- while ($0 ~ brace ".*" brace) {
- sub(brace, opening)
- sub(brace, closing)
+function surround(brace, opening, closing, blen, single_surround) {
+ if (blen == "") { blen = length(brace) }
+
+ while (match($0, brace "[^" brace "]+" brace)) {
+ elem = opening substr($0, RSTART + blen, RLENGTH - 2 * blen) closing
+ $0 = substr($0, 1, RSTART - 1) elem substr($0, RSTART + RLENGTH)
+
+ if (single_surround != "") { return; }
}
}
{
+ ## Make sure <em> is on the inside for long chains
+ ## E.g. *****a***** will be the same as ****_a_****
+ surround("___" , "<strong><em>", "</em></strong>", 3, "oneshot")
+ surround("\\*\\*\\*", "<strong><em>", "</em></strong>", 3, "oneshot")
+
surround("__" , "<strong>", "</strong>")
surround("_" , "<em>" , "</em>")
- surround("\\*\\*", "<strong>", "</strong>")
- surround("\\*" , "<em>" , "</em>")
+ surround("\\*\\*", "<strong>", "</strong>", 2)
+ surround("\\*" , "<em>" , "</em>", 1)
surround("~~" , "<s>" , "</s>")
surround("~" , "<sub>" , "</sub>")
- surround("\\^" , "<sup>" , "</sup>")
+ surround("\\^" , "<sup>" , "</sup>", 1)
surround("``" , "<code>" , "</code>")
surround("`" , "<code>" , "</code>")
}