diff options
| Commit | 77226b4f56a25cb9b791f93b0d9cea66f3b1ff46 (patch) | |
|---|---|---|
| Author | 2024-12-31 10:21:24 +0200 | |
| Committer | 2024-12-31 10:21:24 +0200 | |
| Files | 5ee2ca99747f794c64090ea85f4edf7fba5e0d8c /single.awk | |
| csg-77226b4f56a25cb9b791f93b0d9cea66f3b1ff46.tar csg-77226b4f56a25cb9b791f93b0d9cea66f3b1ff46.tar.gz csg-77226b4f56a25cb9b791f93b0d9cea66f3b1ff46.zip | ||
| Parent | 1a4e8a89d2a331913e653d439e16e4138cfaf6e9 (diff) | |
fix(single): Surround properly handles long chains of * or _
1 files changed, 16 insertions, 7 deletions
| -rw-r--r-- | single.awk | 23 |
@@ -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>") } |
