boxwood 0.61.2 → 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 +18 -11
- 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
|
})
|
|
@@ -110,11 +110,14 @@ const ALIASES = {
|
|
|
110
110
|
const attributes = (options) => {
|
|
111
111
|
const result = []
|
|
112
112
|
for (const key in options) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
const value = options[key]
|
|
114
|
+
if (value) {
|
|
115
|
+
if (BOOLEAN_ATTRIBUTES.includes(key)) {
|
|
116
|
+
result.push(key)
|
|
117
|
+
} else {
|
|
118
|
+
const name = ALIASES[key] || key
|
|
119
|
+
result.push(name + '=' + '"' + options[key] + '"')
|
|
120
|
+
}
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
123
|
return result.join(' ')
|
|
@@ -140,7 +143,11 @@ const SELF_CLOSING_TAGS = [
|
|
|
140
143
|
'!DOCTYPE html',
|
|
141
144
|
]
|
|
142
145
|
|
|
143
|
-
const
|
|
146
|
+
const isUnescapedTag = (name) => {
|
|
147
|
+
return !['script', 'style', 'template'].includes(name)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const render = (input, escape = true) => {
|
|
144
151
|
if (input.ignore) {
|
|
145
152
|
return ''
|
|
146
153
|
}
|
|
@@ -151,7 +158,7 @@ const render = (input) => {
|
|
|
151
158
|
return input.toString()
|
|
152
159
|
}
|
|
153
160
|
if (typeof input === 'string') {
|
|
154
|
-
return escape(input)
|
|
161
|
+
return escape ? escapeHTML(input) : input
|
|
155
162
|
}
|
|
156
163
|
if (input.name === 'fragment') {
|
|
157
164
|
return render(input.children)
|
|
@@ -167,7 +174,7 @@ const render = (input) => {
|
|
|
167
174
|
`<${input.name} ` +
|
|
168
175
|
attributes(input.attributes) +
|
|
169
176
|
'>' +
|
|
170
|
-
render(input.children) +
|
|
177
|
+
render(input.children, isUnescapedTag(input.name)) +
|
|
171
178
|
`</${input.name}>`
|
|
172
179
|
)
|
|
173
180
|
}
|
|
@@ -177,7 +184,7 @@ const render = (input) => {
|
|
|
177
184
|
)
|
|
178
185
|
}
|
|
179
186
|
if (input.children) {
|
|
180
|
-
return `<${input.name}>` + render(input.children) + `</${input.name}>`
|
|
187
|
+
return `<${input.name}>` + render(input.children, isUnescapedTag(input.name)) + `</${input.name}>`
|
|
181
188
|
}
|
|
182
189
|
return `<${input.name}></${input.name}>`
|
|
183
190
|
}
|
|
@@ -400,7 +407,7 @@ module.exports = {
|
|
|
400
407
|
compile,
|
|
401
408
|
classes,
|
|
402
409
|
doctype,
|
|
403
|
-
escape,
|
|
410
|
+
escape: escapeHTML,
|
|
404
411
|
fragment,
|
|
405
412
|
css,
|
|
406
413
|
js,
|