boxwood 0.61.3 → 0.61.5

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.
Files changed (2) hide show
  1. package/index.js +24 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -13,12 +13,21 @@ async function compile(path) {
13
13
  if (node.name === 'head') {
14
14
  nodes.head = node
15
15
  }
16
+ if (node.name === 'body') {
17
+ nodes.body = node
18
+ }
16
19
  if (node.name === 'style') {
17
- styles.push(node.children)
20
+ const css = node.children
21
+ if (!styles.includes(css)) {
22
+ styles.push(css)
23
+ }
18
24
  node.ignore = true
19
25
  }
20
26
  if (node.name === 'script') {
21
- scripts.push(node.children)
27
+ const js = node.children
28
+ if (!scripts.includes(js)) {
29
+ scripts.push(js)
30
+ }
22
31
  node.ignore = true
23
32
  }
24
33
  if (Array.isArray(node)) {
@@ -35,8 +44,10 @@ async function compile(path) {
35
44
  children: styles.join(''),
36
45
  })
37
46
  }
47
+ }
48
+ if (nodes.body) {
38
49
  if (scripts.length > 0) {
39
- nodes.head.children.push({
50
+ nodes.body.children.push({
40
51
  name: 'script',
41
52
  children: scripts.join(''),
42
53
  })
@@ -57,7 +68,7 @@ const ENTITIES = {
57
68
 
58
69
  const REGEXP = /[&<>'"]/g
59
70
 
60
- const escape = (string) => {
71
+ const escapeHTML = (string) => {
61
72
  return String.prototype.replace.call(string, REGEXP, function (character) {
62
73
  return ENTITIES[character]
63
74
  })
@@ -143,7 +154,11 @@ const SELF_CLOSING_TAGS = [
143
154
  '!DOCTYPE html',
144
155
  ]
145
156
 
146
- const render = (input) => {
157
+ const isUnescapedTag = (name) => {
158
+ return !['script', 'style', 'template'].includes(name)
159
+ }
160
+
161
+ const render = (input, escape = true) => {
147
162
  if (input.ignore) {
148
163
  return ''
149
164
  }
@@ -154,7 +169,7 @@ const render = (input) => {
154
169
  return input.toString()
155
170
  }
156
171
  if (typeof input === 'string') {
157
- return escape(input)
172
+ return escape ? escapeHTML(input) : input
158
173
  }
159
174
  if (input.name === 'fragment') {
160
175
  return render(input.children)
@@ -170,7 +185,7 @@ const render = (input) => {
170
185
  `<${input.name} ` +
171
186
  attributes(input.attributes) +
172
187
  '>' +
173
- render(input.children) +
188
+ render(input.children, isUnescapedTag(input.name)) +
174
189
  `</${input.name}>`
175
190
  )
176
191
  }
@@ -180,7 +195,7 @@ const render = (input) => {
180
195
  )
181
196
  }
182
197
  if (input.children) {
183
- return `<${input.name}>` + render(input.children) + `</${input.name}>`
198
+ return `<${input.name}>` + render(input.children, isUnescapedTag(input.name)) + `</${input.name}>`
184
199
  }
185
200
  return `<${input.name}></${input.name}>`
186
201
  }
@@ -403,7 +418,7 @@ module.exports = {
403
418
  compile,
404
419
  classes,
405
420
  doctype,
406
- escape,
421
+ escape: escapeHTML,
407
422
  fragment,
408
423
  css,
409
424
  js,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "0.61.3",
3
+ "version": "0.61.5",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "scripts": {