diff options
Diffstat (limited to 'ht.awk')
-rwxr-xr-x | ht.awk | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/ht.awk b/ht.awk index 7581cdb..c15ccc0 100755 --- a/ht.awk +++ b/ht.awk | |||
@@ -62,6 +62,10 @@ $0 ~ ("^" COMMENT_DELIM) { | |||
62 | } else { | 62 | } else { |
63 | sep = "\n" | 63 | sep = "\n" |
64 | } | 64 | } |
65 | # Sanitize HTML | ||
66 | gsub(/&/, "\\\\\\&", $0) | ||
67 | gsub(/</, "\\\\\\<", $0) | ||
68 | gsub(/>/, "\\\\\\>", $0) | ||
65 | # Loop through BLOCK_TYPES | 69 | # Loop through BLOCK_TYPES |
66 | for (bt in BLOCK_TYPES) { | 70 | for (bt in BLOCK_TYPES) { |
67 | if (match($0, "^" bt "[ \t]*")) { | 71 | if (match($0, "^" bt "[ \t]*")) { |
@@ -105,8 +109,26 @@ $0 ~ ("^" COMMENT_DELIM) { | |||
105 | if (match($0, "^" lt "[ \t]*")) { | 109 | if (match($0, "^" lt "[ \t]*")) { |
106 | $0 = substr($0, RSTART + RLENGTH) | 110 | $0 = substr($0, RSTART + RLENGTH) |
107 | templ = LINE_TYPES[lt] | 111 | templ = LINE_TYPES[lt] |
108 | while (match(templ, /\$[0-9]+/)) { | 112 | while (match(templ, /\$[0-9-]+/)) { |
109 | sub(/\$[0-9]+/, $(substr(templ, RSTART + 1, RLENGTH - 1)), templ) | 113 | if (substr(templ, RSTART + 1, 1) == "-") { |
114 | # Up to $field | ||
115 | f = "" | ||
116 | n = substr(templ, RSTART + 2, RLENGTH - 2) | ||
117 | for (i = 1; i <= n; i++) { | ||
118 | f = f (f ? " " : "") $i | ||
119 | } | ||
120 | sub(/\$[0-9-]+/, f, templ) | ||
121 | } else if (substr(templ, RSTART + RLENGTH - 1, 1) == "-") { | ||
122 | # $Field to end | ||
123 | f = "" | ||
124 | n = substr(templ, RSTART + 1, RLENGTH - 2) | ||
125 | for (i = n; i <= NF; i++) { | ||
126 | f = f (f ? " " : "") $i | ||
127 | } | ||
128 | sub(/\$[0-9-]+/, f, templ) | ||
129 | } else { | ||
130 | sub(/\$[0-9]+/, $(substr(templ, RSTART + 1, RLENGTH - 1)), templ) | ||
131 | } | ||
110 | } | 132 | } |
111 | $0 = templ | 133 | $0 = templ |
112 | } | 134 | } |