Summary Files Commits Branches @commit @diff @stats
path: root / single.awk
diff options
context:
space:
mode:
1 files changed, 24 insertions, 2 deletions
-rw-r--r--single.awk26
diff --git a/single.awk b/single.awk
index ab207a1..e19117d 100644
--- a/single.awk
+++ b/single.awk
@@ -18,9 +18,9 @@
# [x] Images
# [x] Inline
# [x] Reference
-# [.] Other
+# [x] Other
# [x] Autolinks
-# [ ] Escapes
+# [x] Escapes
#
# [ ] Non-standard features
# [ ] Strikethrough ~~...~~
@@ -83,6 +83,15 @@ BEGIN {
for (i = 1; i < 97; ++i) {
char_to_dec[char(ascii, i)] = 31 + i
}
+
+ ## We do character escaping by substituting the escape with some
+ ## "useless" characters, which we're confident won't appear in actual text.
+ ## These are from decimal value 14 to 28 inclusive. They're blank characters,
+ ## related to shifting, device control and data transmission.
+ escapable = "\\`*_{}[]()#+-.!"
+ for (i = 1; i < 16; ++i) {
+ escapes[char(escapable, i)] = sprintf("%c", 13 + i)
+ }
}
{
@@ -108,6 +117,13 @@ BEGIN {
next
}
+# Escapes
+!inside_codeblock && /\\[-\\`*_{}\[\]()#+.!]/ {
+ while (match($0, /\\[-\\`*_{}\[\]()#+.!]/)) {
+ sub_match(escapes[char($0, RSTART + 1)])
+ }
+}
+
# Blockquotes
blockquote_level > 0 && empty0 {
for (P1 = P1 ORS; blockquote_level > 0; --blockquote_level) {
@@ -330,6 +346,12 @@ function __buffered_print() {
N1 = ""
}
}
+
+ ## Fix escaped characters
+ for (i = 1; i < 16; ++i) {
+ esc = char(escapable, i)
+ gsub(escapes[esc], esc, P2)
+ }
}
END {