diff options
| Commit | ade38ab69c5fe8cd7e35395582addac9e037bc3f (patch) | |
|---|---|---|
| Author | 2024-12-31 16:47:18 +0200 | |
| Committer | 2024-12-31 17:04:21 +0200 | |
| Files | e37749e24e271a9859fb28e3de99923c10db35c6 /single.awk | |
| csg-ade38ab69c5fe8cd7e35395582addac9e037bc3f.tar csg-ade38ab69c5fe8cd7e35395582addac9e037bc3f.tar.gz csg-ade38ab69c5fe8cd7e35395582addac9e037bc3f.zip | ||
| Parent | 622d898e1637d01e14c2e92b913214857c00f901 (diff) | |
feat(single): Impelement emphasis span elements
1 files changed, 39 insertions, 2 deletions
| -rw-r--r-- | single.awk | 41 |
@@ -9,12 +9,12 @@ # [ ] Lists # [x] Code blocks # [x] Horizontal rules -# [ ] Span elements +# [.] Span elements # [ ] Links # [ ] Inline # [ ] Reference -# [ ] Emphasis # [ ] Code +# [x] Emphasis # [ ] Images # [ ] Inline # [ ] Reference @@ -150,6 +150,43 @@ inside_codeblock && ! /^[ \t]*$/ { not_paragraph = 1 } +# Emphasis +function sub_match(replacement) { + $0 = substr($0, 1, RSTART - 1) replacement substr($0, RSTART + RLENGTH) +} +function surround(brace, left, right, blen) { + if (blen == "") { blen = length(brace) } + if (match($0, brace "[^" brace "]+" brace)) { + elem = left substr($0, RSTART + blen, RLENGTH - 2*blen) right + sub_match(elem) + return 1; + } + return 0 +} +function gsurround(brace, left, right, blen) { + while (surround(brace, left, right, blen)) {} + + if (blen == 1) { + gsub("\\\\", "", brace) + ## Surrounding a single character span with spaces should make it a + ## literal char. This is inelegant but functional. + gsub(" " left " ", " " brace " ") + gsub(" " right " ", " " brace " ") + } +} + +{ + ## Make sure <em> is on the inside for long chains + ## E.g. *****a***** will be the same as ****_a_**** + surround("___" , "<strong><em>", "</em></strong>") + surround("\\*\\*\\*", "<strong><em>", "</em></strong>", 3) + + gsurround("__" , "<strong>", "</strong>") + gsurround("_" , "<em>" , "</em>") + gsurround("\\*\\*", "<strong>", "</strong>", 2) + gsurround("\\*" , "<em>" , "</em>", 1) +} + # Paragraph emptyP1 && !empty0 && !not_paragraph { $0 = "<p>" $0 } !emptyP1 && empty0 && !not_paragraph_p1 { P1 = P1 "</p>" } |
