aboutsummaryrefslogtreecommitdiff
path: root/emparse
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-30 13:32:29 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-30 13:32:29 +0000
commit34edc530941a6195dd93bf8c8c87c609e2fb39db (patch)
tree8ffb3aa2b291fe2bbde8197be285aaf4e804ef64 /emparse
parentd165d39c08ebc8be6ef3662022196758ef580f80 (diff)
downloadem-34edc530941a6195dd93bf8c8c87c609e2fb39db.tar.gz
Fix HTML character escaping
Diffstat (limited to 'emparse')
-rwxr-xr-xemparse17
1 files changed, 6 insertions, 11 deletions
diff --git a/emparse b/emparse
index 5fb9397..0f86ee3 100755
--- a/emparse
+++ b/emparse
@@ -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("&", "\\&amp;")
- gsub("<", "\\&lt;")
- gsub(">", "\\&gt;")
- } else {
- gsub("&", "\\&amp;", s)
- gsub("<", "\\&lt;", s)
- gsub(">", "\\&gt;", s)
- }
+ gsub("&", "\\&amp;", s)
+ gsub("<", "\\&lt;", s)
+ gsub(">", "\\&gt;", s)
+ return s
}