diff options
author | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-05-19 21:04:40 -0400 |
---|---|---|
committer | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-05-19 21:04:40 -0400 |
commit | 3711e509323b11ebf24f8379c018c9fd30458a8b (patch) | |
tree | 515ee5a83011e8c4a48d24cb90969ec48590ad99 | |
parent | 7110814c69398f04cb2b100e233c34f97ad6ccd1 (diff) |
Escape HTML
-rwxr-xr-x | gemini.filter.dpi | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/gemini.filter.dpi b/gemini.filter.dpi index 17e5c5a..2fc7d64 100755 --- a/gemini.filter.dpi +++ b/gemini.filter.dpi @@ -27,6 +27,12 @@ render_gemini() { then ansi2html else cat fi | awk ' + function escape_html(str) { + gsub(/&/, "\\&", str) + gsub(/</, "\\<", str) + gsub(/>/, "\\>", str) + return str + } BEGIN { print "<!doctype html><body><style>"\ "div { font:monospace; white-space:pre-wrap; }\n"\ @@ -58,7 +64,7 @@ render_gemini() { } match($0, /^\*+\s*/) text = substr($0, RLENGTH+1) - printf "<li>%s</li>\n", text + printf "<li>%s</li>\n", escape_html(text) next } /^#+/ { @@ -66,7 +72,8 @@ render_gemini() { tag = "h" RLENGTH match($0, /^(#+\s*)/) text = substr($0, RLENGTH+1) - printf "<%s style=\"font:sans-serif\">%s</%s>\n", tag, text, tag + html = escape_html(text) + printf "<%s style=\"font:sans-serif\">%s</%s>\n", tag, html, tag next } /^=>/ { @@ -77,7 +84,8 @@ render_gemini() { href = substr(href, 0, RLENGTH) } sub(/:1965/, "", href) - printf "<div><a href=\"%s\">%s</a></div>\n", href, text + html = escape_html(text) + printf "<div><a href=\"%s\">%s</a></div>\n", href, html next } /^$/ { @@ -85,7 +93,7 @@ render_gemini() { next } { - printf "<div>%s</div>\n", $0 + printf "<div>%s</div>\n", escape_html($0) } END { print "</body>" |