boxwood 0.61.3 → 0.61.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +10 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -57,7 +57,7 @@ const ENTITIES = {
|
|
|
57
57
|
|
|
58
58
|
const REGEXP = /[&<>'"]/g
|
|
59
59
|
|
|
60
|
-
const
|
|
60
|
+
const escapeHTML = (string) => {
|
|
61
61
|
return String.prototype.replace.call(string, REGEXP, function (character) {
|
|
62
62
|
return ENTITIES[character]
|
|
63
63
|
})
|
|
@@ -143,7 +143,11 @@ const SELF_CLOSING_TAGS = [
|
|
|
143
143
|
'!DOCTYPE html',
|
|
144
144
|
]
|
|
145
145
|
|
|
146
|
-
const
|
|
146
|
+
const isUnescapedTag = (name) => {
|
|
147
|
+
return !['script', 'style', 'template'].includes(name)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const render = (input, escape = true) => {
|
|
147
151
|
if (input.ignore) {
|
|
148
152
|
return ''
|
|
149
153
|
}
|
|
@@ -154,7 +158,7 @@ const render = (input) => {
|
|
|
154
158
|
return input.toString()
|
|
155
159
|
}
|
|
156
160
|
if (typeof input === 'string') {
|
|
157
|
-
return escape(input)
|
|
161
|
+
return escape ? escapeHTML(input) : input
|
|
158
162
|
}
|
|
159
163
|
if (input.name === 'fragment') {
|
|
160
164
|
return render(input.children)
|
|
@@ -170,7 +174,7 @@ const render = (input) => {
|
|
|
170
174
|
`<${input.name} ` +
|
|
171
175
|
attributes(input.attributes) +
|
|
172
176
|
'>' +
|
|
173
|
-
render(input.children) +
|
|
177
|
+
render(input.children, isUnescapedTag(input.name)) +
|
|
174
178
|
`</${input.name}>`
|
|
175
179
|
)
|
|
176
180
|
}
|
|
@@ -180,7 +184,7 @@ const render = (input) => {
|
|
|
180
184
|
)
|
|
181
185
|
}
|
|
182
186
|
if (input.children) {
|
|
183
|
-
return `<${input.name}>` + render(input.children) + `</${input.name}>`
|
|
187
|
+
return `<${input.name}>` + render(input.children, isUnescapedTag(input.name)) + `</${input.name}>`
|
|
184
188
|
}
|
|
185
189
|
return `<${input.name}></${input.name}>`
|
|
186
190
|
}
|
|
@@ -403,7 +407,7 @@ module.exports = {
|
|
|
403
407
|
compile,
|
|
404
408
|
classes,
|
|
405
409
|
doctype,
|
|
406
|
-
escape,
|
|
410
|
+
escape: escapeHTML,
|
|
407
411
|
fragment,
|
|
408
412
|
css,
|
|
409
413
|
js,
|