11/**
2- * @typedef {import('mdast').FootnoteReference } FootnoteReference
32 * @typedef {import('mdast').FootnoteDefinition } FootnoteDefinition
3+ * @typedef {import('mdast').FootnoteReference } FootnoteReference
44 * @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
55 * @typedef {import('mdast-util-from-markdown').Extension } FromMarkdownExtension
66 * @typedef {import('mdast-util-from-markdown').Handle } FromMarkdownHandle
7- * @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
87 * @typedef {import('mdast-util-to-markdown').Handle } ToMarkdownHandle
98 * @typedef {import('mdast-util-to-markdown').Map } Map
9+ * @typedef {import('mdast-util-to-markdown').Options } ToMarkdownExtension
1010 */
1111
12+ import { ok as assert } from 'devlop'
1213import { normalizeIdentifier } from 'micromark-util-normalize-identifier'
1314
1415footnoteReference . peek = footnoteReferencePeek
1516
16- // To do: next major: rename `context` -> `state`, `safeOptions` to `info`, use
17- // utilities on `state`.
18-
1917/**
2018 * Create an extension for `mdast-util-from-markdown` to enable GFM footnotes
2119 * in markdown.
@@ -80,9 +78,8 @@ function enterFootnoteDefinitionLabelString() {
8078 */
8179function exitFootnoteDefinitionLabelString ( token ) {
8280 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' )
8683 node . label = label
8784 node . identifier = normalizeIdentifier (
8885 this . sliceSerialize ( token )
@@ -119,9 +116,8 @@ function enterFootnoteCallString() {
119116 */
120117function exitFootnoteCallString ( token ) {
121118 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' )
125121 node . label = label
126122 node . identifier = normalizeIdentifier (
127123 this . sliceSerialize ( token )
@@ -140,13 +136,13 @@ function exitFootnoteCall(token) {
140136 * @type {ToMarkdownHandle }
141137 * @param {FootnoteReference } node
142138 */
143- function footnoteReference ( node , _ , context , safeOptions ) {
144- const tracker = context . createTracker ( safeOptions )
139+ function footnoteReference ( node , _ , state , info ) {
140+ const tracker = state . createTracker ( info )
145141 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' )
148144 value += tracker . move (
149- context . safe ( context . associationId ( node ) , {
145+ state . safe ( state . associationId ( node ) , {
150146 ...tracker . current ( ) ,
151147 before : value ,
152148 after : ']'
@@ -167,13 +163,13 @@ function footnoteReferencePeek() {
167163 * @type {ToMarkdownHandle }
168164 * @param {FootnoteDefinition } node
169165 */
170- function footnoteDefinition ( node , _ , context , safeOptions ) {
171- const tracker = context . createTracker ( safeOptions )
166+ function footnoteDefinition ( node , _ , state , info ) {
167+ const tracker = state . createTracker ( info )
172168 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' )
175171 value += tracker . move (
176- context . safe ( context . associationId ( node ) , {
172+ state . safe ( state . associationId ( node ) , {
177173 ...tracker . current ( ) ,
178174 before : value ,
179175 after : ']'
@@ -185,7 +181,7 @@ function footnoteDefinition(node, _, context, safeOptions) {
185181 )
186182 tracker . shift ( 4 )
187183 value += tracker . move (
188- context . indentLines ( context . containerFlow ( node , tracker . current ( ) ) , map )
184+ state . indentLines ( state . containerFlow ( node , tracker . current ( ) ) , map )
189185 )
190186 exit ( )
191187
0 commit comments