@@ -94,32 +94,41 @@ In browsers with [`esm.sh`][esmsh]:
9494Say our document ` example.md ` contains:
9595
9696``` markdown
97- Hi![^1]
97+ In the Solar System, Mercury[^mercury] and Venus[^venus] have very small tilts.
9898
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.
100106```
101107
102108…and our module ` example.js ` looks as follows:
103109
104110``` js
105111import fs from ' node:fs/promises'
106112import {fromMarkdown } from ' mdast-util-from-markdown'
113+ import {
114+ gfmFootnoteFromMarkdown ,
115+ gfmFootnoteToMarkdown
116+ } from ' mdast-util-gfm-footnote'
107117import {toMarkdown } from ' mdast-util-to-markdown'
108118import {gfmFootnote } from ' micromark-extension-gfm-footnote'
109- import {gfmFootnoteFromMarkdown , gfmFootnoteToMarkdown } from ' mdast-util-gfm-footnote'
110119
111- const doc = await fs .readFile (' example.md' )
120+ const value = await fs .readFile (' example.md' , ' utf8 ' )
112121
113- const tree = fromMarkdown (doc , {
122+ const tree = fromMarkdown (value , {
114123 extensions: [gfmFootnote ()],
115124 mdastExtensions: [gfmFootnoteFromMarkdown ()]
116125})
117126
118127console .log (tree)
119128
120- const out = toMarkdown (tree, {extensions: [gfmFootnoteToMarkdown ()]})
129+ const result = toMarkdown (tree, {extensions: [gfmFootnoteToMarkdown ()]})
121130
122- console .log (out )
131+ console .log (result )
123132```
124133
125134…now running ` node example.js ` yields (positional info removed for brevity):
@@ -131,26 +140,58 @@ console.log(out)
131140 {
132141 type: ' paragraph' ,
133142 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.' }
136148 ]
137149 },
138150 {
139151 type: ' footnoteDefinition' ,
140- identifier: ' 1 ' ,
141- label: ' 1 ' ,
152+ identifier: ' mercury ' ,
153+ label: ' mercury ' ,
142154 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+ }
144181 ]
145182 }
146183 ]
147184}
148185```
149186
150187``` 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.
152192
153- [^1]: big note
193+ [^venus]: **Venus** is the second planet from
194+ the Sun.
154195```
155196
156197## API
0 commit comments