1
1
/**
2
- * @typedef {import('mdast').FootnoteReference } FootnoteReference
3
2
* @typedef {import('mdast').FootnoteDefinition } FootnoteDefinition
3
+ * @typedef {import('mdast').FootnoteReference } FootnoteReference
4
4
* @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
5
5
* @typedef {import('mdast-util-from-markdown').Extension } FromMarkdownExtension
6
6
* @typedef {import('mdast-util-from-markdown').Handle } FromMarkdownHandle
7
- * @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
8
7
* @typedef {import('mdast-util-to-markdown').Handle } ToMarkdownHandle
9
8
* @typedef {import('mdast-util-to-markdown').Map } Map
9
+ * @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
10
10
*/
11
11
12
+ import { ok as assert } from 'devlop'
12
13
import { normalizeIdentifier } from 'micromark-util-normalize-identifier'
13
14
14
15
footnoteReference . peek = footnoteReferencePeek
15
16
16
- // To do: next major: rename `context` -> `state`, `safeOptions` to `info`, use
17
- // utilities on `state`.
18
-
19
17
/**
20
18
* Create an extension for `mdast-util-from-markdown` to enable GFM footnotes
21
19
* in markdown.
@@ -80,9 +78,8 @@ function enterFootnoteDefinitionLabelString() {
80
78
*/
81
79
function exitFootnoteDefinitionLabelString ( token ) {
82
80
const label = this . resume ( )
83
- const node = /** @type {FootnoteDefinition } */ (
84
- this . stack [ this . stack . length - 1 ]
85
- )
81
+ const node = this . stack [ this . stack . length - 1 ]
82
+ assert ( node . type === 'footnoteDefinition' )
86
83
node . label = label
87
84
node . identifier = normalizeIdentifier (
88
85
this . sliceSerialize ( token )
@@ -119,9 +116,8 @@ function enterFootnoteCallString() {
119
116
*/
120
117
function exitFootnoteCallString ( token ) {
121
118
const label = this . resume ( )
122
- const node = /** @type {FootnoteDefinition } */ (
123
- this . stack [ this . stack . length - 1 ]
124
- )
119
+ const node = this . stack [ this . stack . length - 1 ]
120
+ assert ( node . type === 'footnoteReference' )
125
121
node . label = label
126
122
node . identifier = normalizeIdentifier (
127
123
this . sliceSerialize ( token )
@@ -140,13 +136,13 @@ function exitFootnoteCall(token) {
140
136
* @type {ToMarkdownHandle }
141
137
* @param {FootnoteReference } node
142
138
*/
143
- function footnoteReference ( node , _ , context , safeOptions ) {
144
- const tracker = context . createTracker ( safeOptions )
139
+ function footnoteReference ( node , _ , state , info ) {
140
+ const tracker = state . createTracker ( info )
145
141
let value = tracker . move ( '[^' )
146
- const exit = context . enter ( 'footnoteReference' )
147
- const subexit = context . enter ( 'reference' )
142
+ const exit = state . enter ( 'footnoteReference' )
143
+ const subexit = state . enter ( 'reference' )
148
144
value += tracker . move (
149
- context . safe ( context . associationId ( node ) , {
145
+ state . safe ( state . associationId ( node ) , {
150
146
...tracker . current ( ) ,
151
147
before : value ,
152
148
after : ']'
@@ -167,13 +163,13 @@ function footnoteReferencePeek() {
167
163
* @type {ToMarkdownHandle }
168
164
* @param {FootnoteDefinition } node
169
165
*/
170
- function footnoteDefinition ( node , _ , context , safeOptions ) {
171
- const tracker = context . createTracker ( safeOptions )
166
+ function footnoteDefinition ( node , _ , state , info ) {
167
+ const tracker = state . createTracker ( info )
172
168
let value = tracker . move ( '[^' )
173
- const exit = context . enter ( 'footnoteDefinition' )
174
- const subexit = context . enter ( 'label' )
169
+ const exit = state . enter ( 'footnoteDefinition' )
170
+ const subexit = state . enter ( 'label' )
175
171
value += tracker . move (
176
- context . safe ( context . associationId ( node ) , {
172
+ state . safe ( state . associationId ( node ) , {
177
173
...tracker . current ( ) ,
178
174
before : value ,
179
175
after : ']'
@@ -185,7 +181,7 @@ function footnoteDefinition(node, _, context, safeOptions) {
185
181
)
186
182
tracker . shift ( 4 )
187
183
value += tracker . move (
188
- context . indentLines ( context . containerFlow ( node , tracker . current ( ) ) , map )
184
+ state . indentLines ( state . containerFlow ( node , tracker . current ( ) ) , map )
189
185
)
190
186
exit ( )
191
187
0 commit comments