boxwood 2.4.5 → 2.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "2.4.5",
3
+ "version": "2.5.0",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
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,40 @@
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(text)
15
+ } else if (line.startsWith("## ")) {
16
+ const text = line.substring(3)
17
+ return H2(text)
18
+ } else if (line.startsWith("### ")) {
19
+ const text = line.substring(4)
20
+ return H3(text)
21
+ } else if (line.startsWith("#### ")) {
22
+ const text = line.substring(5)
23
+ return H4(text)
24
+ } else if (line.startsWith("##### ")) {
25
+ const text = line.substring(6)
26
+ return H5(text)
27
+ } else if (line.startsWith("###### ")) {
28
+ const text = line.substring(7)
29
+ return H6(text)
30
+ } else if (line.startsWith("> ")) {
31
+ const text = line.substring(2)
32
+ return Blockquote(text)
33
+ }
34
+
35
+ return P(line)
36
+ })
37
+ }
38
+ }
39
+
40
+ module.exports = component(Markdown)