boxwood 2.4.5 → 2.6.0

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 CHANGED
@@ -377,7 +377,7 @@ const render = (input, escape = true) => {
377
377
  // Second most common: arrays (~20% of nodes)
378
378
  if (Array.isArray(input)) {
379
379
  let result = ""
380
- for (let i = 0; i < input.length; i++) {
380
+ for (let i = 0, ilen = input.length; i < ilen; i++) {
381
381
  result += render(input[i])
382
382
  }
383
383
  return result
@@ -393,11 +393,6 @@ const render = (input, escape = true) => {
393
393
  return ""
394
394
  }
395
395
 
396
- // Numbers (~5% of nodes)
397
- if (typeof input === "number") {
398
- return input.toString()
399
- }
400
-
401
396
  // Objects (elements) - check ignore flag first
402
397
  if (input.ignore) {
403
398
  return ""
@@ -412,12 +407,24 @@ const render = (input, escape = true) => {
412
407
  return attrs ? `<${input.name} ${attrs}>` : `<${input.name}>`
413
408
  }
414
409
 
415
- const attrs = input.attributes ? attributes(input.attributes) : ""
416
- const children = render(input.children, !UNESCAPED_TAGS.has(input.name))
410
+ if (input.name) {
411
+ const attrs = input.attributes ? attributes(input.attributes) : ""
412
+ const children = render(input.children, !UNESCAPED_TAGS.has(input.name))
413
+
414
+ return attrs
415
+ ? `<${input.name} ${attrs}>${children}</${input.name}>`
416
+ : `<${input.name}>${children}</${input.name}>`
417
+ }
418
+
419
+ if (typeof input === "number") {
420
+ return input.toString()
421
+ }
422
+
423
+ if (typeof input === "object" && input instanceof Date) {
424
+ return input.toString()
425
+ }
417
426
 
418
- return attrs
419
- ? `<${input.name} ${attrs}>${children}</${input.name}>`
420
- : `<${input.name}>${children}</${input.name}>`
427
+ return ""
421
428
  }
422
429
 
423
430
  const raw = (children) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "2.4.5",
3
+ "version": "2.6.0",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "c8": "^10.1.3",
51
51
  "express": "^5.2.1",
52
52
  "handlebars": "^4.7.8",
53
- "jsdom": "^27.2.0",
53
+ "jsdom": "^27.3.0",
54
54
  "mustache": "^4.2.0",
55
55
  "underscore": "^1.13.7"
56
56
  },
@@ -1,6 +1,6 @@
1
1
  const { css, component, Div } = require("../..")
2
2
 
3
- function Center({ className, style, height, width } = {}, children) {
3
+ function Center({ className, id, style, height, width } = {}, children) {
4
4
  const styleObject = {
5
5
  display: "flex",
6
6
  "justify-content": "center",
@@ -17,7 +17,7 @@ function Center({ className, style, height, width } = {}, children) {
17
17
  `
18
18
 
19
19
  return [
20
- Div({ className: [className, styles.center], style }, children),
20
+ Div({ className: [className, styles.center], id, style }, children),
21
21
  styles.css,
22
22
  ]
23
23
  }
@@ -16,7 +16,7 @@ const normalizeValue = (value) => {
16
16
  }
17
17
 
18
18
  function Container(
19
- { className, style, width = 1200, padding = 16 } = {},
19
+ { className, style, id, width = 1200, padding = 16 } = {},
20
20
  children
21
21
  ) {
22
22
  width = normalizeValue(width)
@@ -39,7 +39,7 @@ function Container(
39
39
  }
40
40
  `
41
41
  return [
42
- Div({ className: [styles.container, className], style }, children),
42
+ Div({ className: [styles.container, className], id, style }, children),
43
43
  styles.css,
44
44
  ]
45
45
  }
package/ui/grid/index.js CHANGED
@@ -8,7 +8,10 @@ const BREAKPOINTS = {
8
8
  sm: "575px",
9
9
  }
10
10
 
11
- function Grid({ className, columns = 3, gap, breakpoint, style }, children) {
11
+ function Grid(
12
+ { className, columns = 3, gap, id, breakpoint, style },
13
+ children
14
+ ) {
12
15
  gap = normalizeGap(gap)
13
16
  breakpoint = normalizeBreakpoint(breakpoint)
14
17
 
@@ -55,7 +58,7 @@ function Grid({ className, columns = 3, gap, breakpoint, style }, children) {
55
58
  `
56
59
 
57
60
  return [
58
- Div({ className: [styles.grid, className], style }, children),
61
+ Div({ className: [styles.grid, className], id, style }, children),
59
62
  styles.css,
60
63
  ]
61
64
  }
package/ui/group/index.js CHANGED
@@ -8,7 +8,18 @@ const {
8
8
  } = require("../normalize")
9
9
 
10
10
  function Group(
11
- { align, className, breakpoint, justify, gap, width, margin, padding, style },
11
+ {
12
+ align,
13
+ className,
14
+ breakpoint,
15
+ id,
16
+ justify,
17
+ gap,
18
+ width,
19
+ margin,
20
+ padding,
21
+ style,
22
+ },
12
23
  children
13
24
  ) {
14
25
  gap = normalizeGap(gap)
@@ -43,7 +54,7 @@ function Group(
43
54
  `
44
55
 
45
56
  return [
46
- Div({ className: [styles.group, className], style }, children),
57
+ Div({ className: [styles.group, className], id, style }, children),
47
58
  styles.css,
48
59
  ]
49
60
  }
package/ui/index.js CHANGED
@@ -3,6 +3,7 @@ const Container = require("./container")
3
3
  const Grid = require("./grid")
4
4
  const Group = require("./group")
5
5
  const Stack = require("./stack")
6
+ const Markdown = require("./markdown")
6
7
 
7
8
  module.exports = {
8
9
  Center,
@@ -10,4 +11,5 @@ module.exports = {
10
11
  Grid,
11
12
  Group,
12
13
  Stack,
14
+ Markdown,
13
15
  }
@@ -0,0 +1,42 @@
1
+ const { component, H1, H2, H3, H4, H5, H6, P, Blockquote } = require("../..")
2
+
3
+ function Markdown(params, children) {
4
+ if (typeof children === "string") {
5
+ const lines = children
6
+ .trim()
7
+ .split("\n")
8
+ .map((line) => line.trim())
9
+ .filter(Boolean)
10
+
11
+ return lines.map((line) => {
12
+ if (line.startsWith("# ")) {
13
+ const text = line.substring(2)
14
+ return H1(params, text)
15
+ } else if (line.startsWith("## ")) {
16
+ const text = line.substring(3)
17
+ return H2(params, text)
18
+ } else if (line.startsWith("### ")) {
19
+ const text = line.substring(4)
20
+ return H3(params, text)
21
+ } else if (line.startsWith("#### ")) {
22
+ const text = line.substring(5)
23
+ return H4(params, text)
24
+ } else if (line.startsWith("##### ")) {
25
+ const text = line.substring(6)
26
+ return H5(params, text)
27
+ } else if (line.startsWith("###### ")) {
28
+ const text = line.substring(7)
29
+ return H6(params, text)
30
+ } else if (line.startsWith("> ")) {
31
+ const text = line.substring(2)
32
+ return Blockquote(params, text)
33
+ }
34
+
35
+ return P(params, line)
36
+ })
37
+ } else {
38
+ return null
39
+ }
40
+ }
41
+
42
+ module.exports = component(Markdown)
package/ui/stack/index.js CHANGED
@@ -7,7 +7,7 @@ const {
7
7
  } = require("../normalize")
8
8
 
9
9
  function Stack(
10
- { align, className, justify, gap, width, margin, padding, style },
10
+ { align, className, id, justify, gap, width, margin, padding, style },
11
11
  children
12
12
  ) {
13
13
  gap = normalizeGap(gap)
@@ -36,7 +36,7 @@ function Stack(
36
36
  `
37
37
 
38
38
  return [
39
- Div({ className: [styles.stack, className], style }, children),
39
+ Div({ className: [styles.stack, className], id, style }, children),
40
40
  styles.css,
41
41
  ]
42
42
  }