diff options
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>" } |
