@@ -94,32 +94,41 @@ In browsers with [`esm.sh`][esmsh]:
94
94
Say our document ` example.md ` contains:
95
95
96
96
``` markdown
97
- Hi![^1]
97
+ In the Solar System, Mercury[^mercury] and Venus[^venus] have very small tilts.
98
98
99
- [^1]: big note
99
+ [^mercury]:
100
+ **Mercury** is the first planet from the Sun and the smallest
101
+ in the Solar System.
102
+
103
+ [^venus]:
104
+ **Venus** is the second planet from
105
+ the Sun.
100
106
```
101
107
102
108
…and our module ` example.js ` looks as follows:
103
109
104
110
``` js
105
111
import fs from ' node:fs/promises'
106
112
import {fromMarkdown } from ' mdast-util-from-markdown'
113
+ import {
114
+ gfmFootnoteFromMarkdown ,
115
+ gfmFootnoteToMarkdown
116
+ } from ' mdast-util-gfm-footnote'
107
117
import {toMarkdown } from ' mdast-util-to-markdown'
108
118
import {gfmFootnote } from ' micromark-extension-gfm-footnote'
109
- import {gfmFootnoteFromMarkdown , gfmFootnoteToMarkdown } from ' mdast-util-gfm-footnote'
110
119
111
- const doc = await fs .readFile (' example.md' )
120
+ const value = await fs .readFile (' example.md' , ' utf8 ' )
112
121
113
- const tree = fromMarkdown (doc , {
122
+ const tree = fromMarkdown (value , {
114
123
extensions: [gfmFootnote ()],
115
124
mdastExtensions: [gfmFootnoteFromMarkdown ()]
116
125
})
117
126
118
127
console .log (tree)
119
128
120
- const out = toMarkdown (tree, {extensions: [gfmFootnoteToMarkdown ()]})
129
+ const result = toMarkdown (tree, {extensions: [gfmFootnoteToMarkdown ()]})
121
130
122
- console .log (out )
131
+ console .log (result )
123
132
```
124
133
125
134
…now running ` node example.js ` yields (positional info removed for brevity):
@@ -131,26 +140,58 @@ console.log(out)
131
140
{
132
141
type: ' paragraph' ,
133
142
children: [
134
- {type: ' text' , value: ' Hi!' },
135
- {type: ' footnoteReference' , identifier: ' 1' , label: ' 1' }
143
+ {type: ' text' , value: ' In the Solar System, Mercury' },
144
+ {type: ' footnoteReference' , identifier: ' mercury' , label: ' mercury' },
145
+ {type: ' text' , value: ' and Venus' },
146
+ {type: ' footnoteReference' , identifier: ' venus' , label: ' venus' },
147
+ {type: ' text' , value: ' have very small tilts.' }
136
148
]
137
149
},
138
150
{
139
151
type: ' footnoteDefinition' ,
140
- identifier: ' 1 ' ,
141
- label: ' 1 ' ,
152
+ identifier: ' mercury ' ,
153
+ label: ' mercury ' ,
142
154
children: [
143
- {type: ' paragraph' , children: [{type: ' text' , value: ' big note' }]}
155
+ {
156
+ type: ' paragraph' ,
157
+ children: [
158
+ {type: ' strong' , children: [{type: ' text' , value: ' Mercury' }]},
159
+ {
160
+ type: ' text' ,
161
+ value:
162
+ ' is the first planet from the Sun and the smallest\n ' +
163
+ ' in the Solar System.'
164
+ }
165
+ ]
166
+ }
167
+ ]
168
+ },
169
+ {
170
+ type: ' footnoteDefinition' ,
171
+ identifier: ' venus' ,
172
+ label: ' venus' ,
173
+ children: [
174
+ {
175
+ type: ' paragraph' ,
176
+ children: [
177
+ {type: ' strong' , children: [{type: ' text' , value: ' Venus' }]},
178
+ {type: ' text' , value: ' is the second planet from\n the Sun.' }
179
+ ]
180
+ }
144
181
]
145
182
}
146
183
]
147
184
}
148
185
```
149
186
150
187
``` markdown
151
- Hi\![^1]
188
+ In the Solar System, Mercury[^mercury] and Venus[^venus] have very small tilts.
189
+
190
+ [^mercury]: **Mercury** is the first planet from the Sun and the smallest
191
+ in the Solar System.
152
192
153
- [^1]: big note
193
+ [^venus]: **Venus** is the second planet from
194
+ the Sun.
154
195
```
155
196
156
197
## API
0 commit comments