From 34edc530941a6195dd93bf8c8c87c609e2fb39db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 30 Jan 2021 13:32:29 +0000 Subject: Fix HTML character escaping --- emparse | 17 ++++++----------- 1 file 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("&", "\\&") - gsub("<", "\\<") - gsub(">", "\\>") - } else { - gsub("&", "\\&", s) - gsub("<", "\\<", s) - gsub(">", "\\>", s) - } + gsub("&", "\\&", s) + gsub("<", "\\<", s) + gsub(">", "\\>", s) + return s } -- cgit v1.2.3