2
2
3
3
Transform [ MDAST] [ ] to [ HAST] [ ] .
4
4
5
- > ** Note** You probably want to use [ remark-rehype] [ ] .
5
+ > ** Note** : You probably want to use [ remark-rehype] [ ] .
6
6
7
7
## Installation
8
8
@@ -51,11 +51,12 @@ root[1] (1:1-2:1, 0-20)
51
51
52
52
Transform the given [ MDAST] [ ] tree to a [ HAST] [ ] tree.
53
53
54
+ ##### Options
55
+
54
56
###### ` options.allowDangerousHTML `
55
57
56
- Whether to allow ` html ` nodes and inject them as raw HTML (` boolean ` ,
57
- default: ` false ` ). Only do this when compiling later with
58
- ` hast-util-to-html ` .
58
+ Whether to allow ` html ` nodes and inject them as raw HTML (` boolean ` , default:
59
+ ` false ` ). Only do this when compiling later with ` hast-util-to-html ` .
59
60
60
61
###### ` options.commonmark `
61
62
@@ -64,15 +65,14 @@ are found. The default behaviour is to prefer the last duplicate definition.
64
65
65
66
###### ` options.handlers `
66
67
67
- Object mapping [ MDAST nodes] [ mdast ] to functions
68
- handling those elements.
68
+ Object mapping [ MDAST nodes] [ mdast ] to functions handling those elements.
69
69
Take a look at [ ` lib/handlers/ ` ] [ handlers ] for examples.
70
70
71
- ###### Returns
71
+ ##### Returns
72
72
73
73
[ ` HASTNode ` ] [ hast ] .
74
74
75
- ###### Note
75
+ ##### Notes
76
76
77
77
* ` yaml ` and ` toml ` nodes are ignored
78
78
* [ ` html ` ] [ mdast-html ] nodes are ignored if ` allowDangerousHTML ` is ` false `
@@ -85,6 +85,111 @@ Take a look at [`lib/handlers/`][handlers] for examples.
85
85
* If ` node.data.hChildren ` is set, it’s used as the element’s HAST
86
86
children
87
87
88
+ ##### Examples
89
+
90
+ ###### ` hName `
91
+
92
+ ` node.data.hName ` in MDAST sets the tag-name of an element in HAST.
93
+ The following [ MDAST] [ ] :
94
+
95
+ ``` js
96
+ {
97
+ type: ' strong' ,
98
+ data: {hName: ' b' },
99
+ children: [{type: ' text' , value: ' Alpha' }]
100
+ }
101
+ ```
102
+
103
+ Yields, in HAST:
104
+
105
+ ``` js
106
+ {
107
+ type: ' element' ,
108
+ tagName: ' b' ,
109
+ properties: {},
110
+ children: [{type: ' text' , value: ' Alpha' }]
111
+ }
112
+ ```
113
+
114
+ ###### ` hProperties `
115
+
116
+ ` node.data.hProperties ` in MDAST sets the properties of an element in HAST.
117
+ The following [ MDAST] [ ] :
118
+
119
+ ``` js
120
+ {
121
+ type: ' image' ,
122
+ src: ' circle.svg' ,
123
+ alt: ' Big red circle on a black background' ,
124
+ title: null
125
+ data: {hProperties: {className: [' responsive' ]}}
126
+ }
127
+ ```
128
+
129
+ Yields, in HAST:
130
+
131
+ ``` js
132
+ {
133
+ type: ' element' ,
134
+ tagName: ' img' ,
135
+ properties: {
136
+ src: ' circle.svg' ,
137
+ alt: ' Big red circle on a black background' ,
138
+ className: [' responsive' ]
139
+ },
140
+ children: []
141
+ }
142
+ ```
143
+
144
+ ###### ` hChildren `
145
+
146
+ ` node.data.hChildren ` in MDAST sets the children of an element in HAST.
147
+ The following [ MDAST] [ ] :
148
+
149
+ ``` js
150
+ {
151
+ type: ' code' ,
152
+ lang: ' js' ,
153
+ data: {
154
+ hChildren: [
155
+ {
156
+ type: ' element' ,
157
+ tagName: ' span' ,
158
+ properties: {className: [' hljs-meta' ]},
159
+ children: [{type: ' text' , value: ' "use strict"' }]
160
+ },
161
+ {type: ' text' , value: ' ;' }
162
+ ]
163
+ },
164
+ value: ' "use strict";'
165
+ }
166
+ ```
167
+
168
+ Yields, in HAST (** note** : the ` pre ` and ` language-js ` class are added
169
+ normal ` mdast-util-to-hast ` functionality):
170
+
171
+ ``` js
172
+ {
173
+ type: ' element' ,
174
+ tagName: ' pre' ,
175
+ properties: {},
176
+ children: [{
177
+ type: ' element' ,
178
+ tagName: ' code' ,
179
+ properties: {className: [' language-js' ]},
180
+ children: [
181
+ {
182
+ type: ' element' ,
183
+ tagName: ' span' ,
184
+ properties: {className: [' hljs-meta' ]},
185
+ children: [{type: ' text' , value: ' "use strict"' }]
186
+ },
187
+ {type: ' text' , value: ' ;' }
188
+ ]
189
+ }]
190
+ }
191
+ ```
192
+
88
193
## Related
89
194
90
195
* [ ` mdast-util-to-nlcst ` ] ( https://github.com/syntax-tree/mdast-util-to-nlcst )
0 commit comments