@@ -17,6 +17,7 @@ npm install hastscript
1717var h = require (' hastscript' )
1818var s = require (' hastscript/svg' )
1919
20+ // Child nodes as an array
2021console .log (
2122 h (' .foo#some-id' , [
2223 h (' span' , ' some text' ),
@@ -28,6 +29,17 @@ console.log(
2829 ])
2930)
3031
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+
3143console .log (
3244 s (' svg' , {xmlns: ' http://www.w3.org/2000/svg' , viewbox: ' 0 0 500 500' }, [
3345 s (' title' , ' SVG `<circle>` element' ),
@@ -57,6 +69,22 @@ Yields:
5769 children:
5870 [ { type: ' text' , value: ' delta' },
5971 { 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: [] } ] }
6088{ type: ' element' ,
6189 tagName: ' svg' ,
6290 properties: { xmlns: ' http://www.w3.org/2000/svg' , viewBox: ' 0 0 500 500' },
@@ -73,9 +101,9 @@ Yields:
73101
74102## API
75103
76- ### ` h(selector?[, properties][, children]) `
104+ ### ` h(selector?[, properties][, ... children]) `
77105
78- ### ` s(selector?[, properties][, children]) `
106+ ### ` s(selector?[, properties][, ... children]) `
79107
80108DSL to create virtual [ HAST] [ ] trees for HTML or SVG.
81109
@@ -94,7 +122,7 @@ Map of properties (`Object.<*>`, optional).
94122
95123###### ` children `
96124
97- (List of) child nodes (` string ` , ` Node ` , ` Array.<string|Node> ` , optional).
125+ (Lists of) child nodes (` string ` , ` Node ` , ` Array.<string|Node> ` , optional).
98126When strings are encountered, they are normalised to [ ` text ` ] [ text ] nodes.
99127
100128##### Returns
0 commit comments