From 85d8a2d6b4a5335db6e4bda799c454664fb859d1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 13 Aug 2022 19:14:26 -0500 Subject: Move template-escaping before raw handling --- ht.awk | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ht.awk b/ht.awk index 04506a9..bf9db1e 100755 --- a/ht.awk +++ b/ht.awk @@ -14,6 +14,19 @@ BEGIN { ATTR = DEFATTR } +# Sure, let's do templating! This makes it less... weird. +# This has to come before raw handling so that code doesn't get expanded in raw sections. +/\$/ { + if (RAW) { + gsub(/\$/, "\\\\&", $0) + } else { + # XXX: This is probably the dumbest way to do it. + gsub(/\$\$/, "$\a", $0) + gsub(/\$[^\a]/, "\\\\&", $0) + gsub(/\$\a/, "$", $0) + } +} + # Handle raw sections $0 ~ CONFIG["raw_delim"] { RAW = ! RAW @@ -45,14 +58,6 @@ $0 ~ ("^" COMMENT_DELIM) { next } -# Sure, let's do templating! This makes it less... weird. -/\$/ { - # XXX: This is probably the dumbest way to do it. - gsub(/\$\$/, "$\a", $0) - gsub(/\$[^\a]/, "\\\\&", $0) - gsub(/\$\a/, "$", $0) -} - # Blocks of text /./ { # EOL escape -- cgit 1.4.1-21-gabe81