1
- # hastscript [ ![ Build ] [ build-badge ]] [ build ] [ ![ Coverage ] [ coverage-badge ]] [ coverage ] [ ![ Downloads ] [ downloads-badge ]] [ downloads ] [ ![ Size ] [ size-badge ]] [ size ] [ ![ Chat ] [ chat-badge ]] [ chat ]
1
+ # hastscript
2
2
3
- [ Hyperscript] [ ] (and [ ` virtual-hyperscript ` ] [ virtual-hyperscript ] )
4
- compatible DSL for creating virtual [ HAST] [ ] trees in HTML and SVG.
3
+ [ ![ Build] [ build-badge ]] [ build ]
4
+ [ ![ Coverage] [ coverage-badge ]] [ coverage ]
5
+ [ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
+ [ ![ Size] [ size-badge ]] [ size ]
7
+ [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8
+ [ ![ Backers] [ backers-badge ]] [ collective ]
9
+ [ ![ Chat] [ chat-badge ]] [ chat ]
5
10
6
- ## Installation
11
+ [ ** hast** ] [ hast ] utility to create [ * trees* ] [ tree ] in HTML or SVG.
12
+
13
+ Similar to [ hyperscript] [ ] (and [ ` virtual-hyperscript ` ] [ virtual-hyperscript ] )
14
+ but for [ ** hast** ] [ hast ] .
15
+
16
+ ## Install
7
17
8
18
[ npm] [ ] :
9
19
10
- ``` bash
20
+ ``` sh
11
21
npm install hastscript
12
22
```
13
23
14
24
## Usage
15
25
16
- ``` javascript
26
+ ``` js
17
27
var h = require (' hastscript' )
18
28
var s = require (' hastscript/svg' )
19
29
20
- // Child nodes as an array
30
+ // Children as an array:
21
31
console .log (
22
32
h (' .foo#some-id' , [
23
33
h (' span' , ' some text' ),
@@ -29,7 +39,7 @@ console.log(
29
39
])
30
40
)
31
41
32
- // Child nodes as arguments
42
+ // Children as arguments:
33
43
console .log (
34
44
h (
35
45
' form' ,
@@ -40,6 +50,7 @@ console.log(
40
50
)
41
51
)
42
52
53
+ // SVG:
43
54
console .log (
44
55
s (' svg' , {xmlns: ' http://www.w3.org/2000/svg' , viewbox: ' 0 0 500 500' }, [
45
56
s (' title' , ' SVG `<circle>` element' ),
@@ -51,52 +62,75 @@ console.log(
51
62
Yields:
52
63
53
64
``` js
54
- { type: ' element' ,
65
+ {
66
+ type: ' element' ,
55
67
tagName: ' div' ,
56
- properties: { className: [ ' foo' ], id: ' some-id' },
57
- children:
58
- [ { type: ' element' ,
59
- tagName: ' span' ,
60
- properties: {},
61
- children: [ { type: ' text' , value: ' some text' } ] },
62
- { type: ' element' ,
63
- tagName: ' input' ,
64
- properties: { type: ' text' , value: ' foo' },
65
- children: [] },
66
- { type: ' element' ,
67
- tagName: ' a' ,
68
- properties: { className: [ ' alpha' , ' bravo' , ' charlie' ], download: true },
69
- children:
70
- [ { type: ' text' , value: ' delta' },
71
- { type: ' text' , value: ' echo' } ] } ] }
72
- { type: ' element' ,
68
+ properties: {className: [' foo' ], id: ' some-id' },
69
+ children: [
70
+ {
71
+ type: ' element' ,
72
+ tagName: ' span' ,
73
+ properties: {},
74
+ children: [{type: ' text' , value: ' some text' }]
75
+ },
76
+ {
77
+ type: ' element' ,
78
+ tagName: ' input' ,
79
+ properties: {type: ' text' , value: ' foo' },
80
+ children: []
81
+ },
82
+ {
83
+ type: ' element' ,
84
+ tagName: ' a' ,
85
+ properties: {className: [' alpha' , ' bravo' , ' charlie' ], download: true },
86
+ children: [{type: ' text' , value: ' delta' }, {type: ' text' , value: ' echo' }]
87
+ }
88
+ ]
89
+ }
90
+ {
91
+ type: ' element' ,
73
92
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: [] } ] }
88
- { type: ' element' ,
93
+ properties: {method: ' POST' },
94
+ children: [
95
+ {
96
+ type: ' element' ,
97
+ tagName: ' input' ,
98
+ properties: {type: ' text' , name: ' foo' },
99
+ children: []
100
+ },
101
+ {
102
+ type: ' element' ,
103
+ tagName: ' input' ,
104
+ properties: {type: ' text' , name: ' bar' },
105
+ children: []
106
+ },
107
+ {
108
+ type: ' element' ,
109
+ tagName: ' input' ,
110
+ properties: {type: ' submit' , value: ' send' },
111
+ children: []
112
+ }
113
+ ]
114
+ }
115
+ {
116
+ type: ' element' ,
89
117
tagName: ' svg' ,
90
- properties: { xmlns: ' http://www.w3.org/2000/svg' , viewBox: ' 0 0 500 500' },
91
- children:
92
- [ { type: ' element' ,
93
- tagName: ' title' ,
94
- properties: {},
95
- children: [ { type: ' text' , value: ' SVG `<circle>` element' } ] },
96
- { type: ' element' ,
97
- tagName: ' circle' ,
98
- properties: { cx: 120 , cy: 120 , r: 100 },
99
- children: [] } ] }
118
+ properties: {xmlns: ' http://www.w3.org/2000/svg' , viewBox: ' 0 0 500 500' },
119
+ children: [
120
+ {
121
+ type: ' element' ,
122
+ tagName: ' title' ,
123
+ properties: {},
124
+ children: [{type: ' text' , value: ' SVG `<circle>` element' }]
125
+ },
126
+ {
127
+ type: ' element' ,
128
+ tagName: ' circle' ,
129
+ properties: {cx: 120 , cy: 120 , r: 100 },
130
+ children: []
131
+ }
132
+ ]
133
+ }
100
134
```
101
135
102
136
## API
@@ -111,8 +145,8 @@ DSL to create virtual [HAST][] trees for HTML or SVG.
111
145
112
146
###### ` selector `
113
147
114
- Simple CSS selector (` string ` , optional). Can contain a tag name ( ` foo ` ), IDs
115
- (` #bar ` ), and classes (` .baz ` ).
148
+ Simple CSS selector (` string ` , optional).
149
+ Can contain a tag name ( ` foo ` ), IDs (` #bar ` ), and classes (` .baz ` ).
116
150
If there is no tag name in the selector, ` h ` defaults to a ` div ` element,
117
151
and ` s ` to a ` g ` element.
118
152
@@ -123,19 +157,21 @@ Map of properties (`Object.<*>`, optional).
123
157
###### ` children `
124
158
125
159
(Lists of) child nodes (` string ` , ` Node ` , ` Array.<string|Node> ` , optional).
126
- When strings are encountered, they are normalised to [ ` text ` ] [ text ] nodes.
160
+ When strings are encountered, they are mapped to [ ` text ` ] [ text ] nodes.
127
161
128
162
##### Returns
129
163
130
164
[ ` Element ` ] [ element ] .
131
165
132
166
## Contribute
133
167
134
- See [ ` contributing.md ` in ` syntax-tree/hast ` ] [ contributing ] for ways to get
168
+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
135
169
started.
170
+ See [ ` support.md ` ] [ support ] for ways to get help.
136
171
137
- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
138
- repository, organisation, or community you agree to abide by its terms.
172
+ This project has a [ Code of Conduct] [ coc ] .
173
+ By interacting with this repository, organisation, or community you agree to
174
+ abide by its terms.
139
175
140
176
## License
141
177
@@ -159,26 +195,36 @@ repository, organisation, or community you agree to abide by its terms.
159
195
160
196
[ size ] : https://bundlephobia.com/result?p=hastscript
161
197
198
+ [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
199
+
200
+ [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
201
+
202
+ [ collective ] : https://opencollective.com/unified
203
+
162
204
[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
163
205
164
- [ chat ] : https://spectrum.chat/unified/rehype
206
+ [ chat ] : https://spectrum.chat/unified/syntax-tree
165
207
166
208
[ npm ] : https://docs.npmjs.com/cli/install
167
209
168
210
[ license ] : license
169
211
170
212
[ author ] : https://wooorm.com
171
213
172
- [ hast ] : https://github.com/syntax-tree/hast
214
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
173
215
174
- [ element ] : https://github.com/syntax-tree/hast#element
216
+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
217
+
218
+ [ coc ] : https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
175
219
176
220
[ virtual-hyperscript ] : https://github.com/Matt-Esch/virtual-dom/tree/master/virtual-hyperscript
177
221
178
222
[ hyperscript ] : https://github.com/dominictarr/hyperscript
179
223
180
- [ text ] : https://github.com/syntax-tree/unist#text
224
+ [ tree ] : https://github.com/syntax-tree/unist#tree
181
225
182
- [ contributing ] : https://github.com/syntax-tree/hast/blob/master/contributing.md
226
+ [ hast ] : https://github.com/syntax-tree/hast
227
+
228
+ [ element ] : https://github.com/syntax-tree/hast#element
183
229
184
- [ coc ] : https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md
230
+ [ text ] : https://github.com/syntax-tree/hast#text
0 commit comments