aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
}