@@ -17,6 +17,7 @@ npm install hastscript
17
17
var h = require (' hastscript' )
18
18
var s = require (' hastscript/svg' )
19
19
20
+ // Child nodes as an array
20
21
console .log (
21
22
h (' .foo#some-id' , [
22
23
h (' span' , ' some text' ),
@@ -28,6 +29,17 @@ console.log(
28
29
])
29
30
)
30
31
32
+ // Child nodes as arguments
33
+ console .log (
34
+ h (
35
+ ' form' ,
36
+ {method: ' POST' },
37
+ h (' input' , {type: ' text' , name: ' foo' }),
38
+ h (' input' , {type: ' text' , name: ' bar' }),
39
+ h (' input' , {type: ' submit' , value: ' send' })
40
+ )
41
+ )
42
+
31
43
console .log (
32
44
s (' svg' , {xmlns: ' http://www.w3.org/2000/svg' , viewbox: ' 0 0 500 500' }, [
33
45
s (' title' , ' SVG `<circle>` element' ),
@@ -57,6 +69,22 @@ Yields:
57
69
children:
58
70
[ { type: ' text' , value: ' delta' },
59
71
{ type: ' text' , value: ' echo' } ] } ] }
72
+ { type: ' element' ,
73
+ tagName: ' form' ,
74
+ properties: { method: ' POST' },
75
+ children:
76
+ [ { type: ' element' ,
77
+ tagName: ' input' ,
78
+ properties: { type: ' text' , name: ' foo' },
79
+ children: [] },
80
+ { type: ' element' ,
81
+ tagName: ' input' ,
82
+ properties: { type: ' text' , name: ' bar' },
83
+ children: [] },
84
+ { type: ' element' ,
85
+ tagName: ' input' ,
86
+ properties: { type: ' submit' , value: ' send' },
87
+ children: [] } ] }
60
88
{ type: ' element' ,
61
89
tagName: ' svg' ,
62
90
properties: { xmlns: ' http://www.w3.org/2000/svg' , viewBox: ' 0 0 500 500' },
@@ -73,9 +101,9 @@ Yields:
73
101
74
102
## API
75
103
76
- ### ` h(selector?[, properties][, children]) `
104
+ ### ` h(selector?[, properties][, ... children]) `
77
105
78
- ### ` s(selector?[, properties][, children]) `
106
+ ### ` s(selector?[, properties][, ... children]) `
79
107
80
108
DSL to create virtual [ HAST] [ ] trees for HTML or SVG.
81
109
@@ -94,7 +122,7 @@ Map of properties (`Object.<*>`, optional).
94
122
95
123
###### ` children `
96
124
97
- (List of) child nodes (` string ` , ` Node ` , ` Array.<string|Node> ` , optional).
125
+ (Lists of) child nodes (` string ` , ` Node ` , ` Array.<string|Node> ` , optional).
98
126
When strings are encountered, they are normalised to [ ` text ` ] [ text ] nodes.
99
127
100
128
##### Returns
0 commit comments