diff options
author | John Ankarström <john@ankarstrom.se> | 2021-01-30 13:32:29 +0000 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-01-30 13:32:29 +0000 |
commit | 34edc530941a6195dd93bf8c8c87c609e2fb39db (patch) | |
tree | 8ffb3aa2b291fe2bbde8197be285aaf4e804ef64 | |
parent | d165d39c08ebc8be6ef3662022196758ef580f80 (diff) | |
download | em-34edc530941a6195dd93bf8c8c87c609e2fb39db.tar.gz |
Fix HTML character escaping
-rwxr-xr-x | emparse | 17 |
1 files changed, 6 insertions, 11 deletions
@@ -26,7 +26,7 @@ expectblock && /^===== .* =====$/ { heading(5, $0); next } expectblock && /^====== .* ======$/ { heading(6, $0); next } expectblock { newblock("p") } -openblock == "pre" { sub("^ ", ""); escape(); printf "%s\n", $0; next } +openblock == "pre" { sub("^ ", ""); $0 = escape($0); printf "%s\n", $0; next } openblock == "ul" && /^ - / { item(1, "ul", line) } openblock == "ol" && /^ [0-9a-z]+\. / { item(1, "ol", line) } @@ -48,7 +48,7 @@ openblock == "dl" && /^ .*: / { term(line) } { format($0) } # inline formatting function format(line) { - escape(line) + line = escape(line) n = split(line, w, "[ ]") for (i = 0; i <= n; i++) { if (w[i] == "") continue; @@ -206,13 +206,8 @@ function ref(v) { } function escape(s) { - if (s == "") { - gsub("&", "\\&") - gsub("<", "\\<") - gsub(">", "\\>") - } else { - gsub("&", "\\&", s) - gsub("<", "\\<", s) - gsub(">", "\\>", s) - } + gsub("&", "\\&", s) + gsub("<", "\\<", s) + gsub(">", "\\>", s) + return s } |