77 * @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
88 * @typedef {import('mdast-util-from-markdown').Token } Token
99 * @typedef {import('mdast-util-to-markdown/lib/types.js').Handle } ToMarkdownHandle
10- * @typedef {import('mdast-util-to-markdown/lib/types.js ').Context } Context
10+ * @typedef {import('mdast-util-to-markdown').State } State
1111 * @typedef {import('mdast-util-to-markdown/lib/types.js').Options } ToMarkdownExtension
1212 * @typedef {import('./complex-types').ContainerDirective } ContainerDirective
1313 * @typedef {import('./complex-types').LeafDirective } LeafDirective
@@ -76,10 +76,12 @@ export const directiveToMarkdown = {
7676 unsafe : [
7777 {
7878 character : '\r' ,
79+ // @ts -expect-error: to do: map.
7980 inConstruct : [ 'leafDirectiveLabel' , 'containerDirectiveLabel' ]
8081 } ,
8182 {
8283 character : '\n' ,
84+ // @ts -expect-error: to do: map.
8385 inConstruct : [ 'leafDirectiveLabel' , 'containerDirectiveLabel' ]
8486 } ,
8587 {
@@ -97,17 +99,26 @@ export const directiveToMarkdown = {
9799 }
98100}
99101
100- /** @type {FromMarkdownHandle } */
102+ /**
103+ * @this {CompileContext}
104+ * @type {FromMarkdownHandle }
105+ */
101106function enterContainer ( token ) {
102107 enter . call ( this , 'containerDirective' , token )
103108}
104109
105- /** @type {FromMarkdownHandle } */
110+ /**
111+ * @this {CompileContext}
112+ * @type {FromMarkdownHandle }
113+ */
106114function enterLeaf ( token ) {
107115 enter . call ( this , 'leafDirective' , token )
108116}
109117
110- /** @type {FromMarkdownHandle } */
118+ /**
119+ * @this {CompileContext}
120+ * @type {FromMarkdownHandle }
121+ */
111122function enterText ( token ) {
112123 enter . call ( this , 'textDirective' , token )
113124}
@@ -130,28 +141,43 @@ function exitName(token) {
130141 node . name = this . sliceSerialize ( token )
131142}
132143
133- /** @type {FromMarkdownHandle } */
144+ /**
145+ * @this {CompileContext}
146+ * @type {FromMarkdownHandle }
147+ */
134148function enterContainerLabel ( token ) {
135149 this . enter (
136150 { type : 'paragraph' , data : { directiveLabel : true } , children : [ ] } ,
137151 token
138152 )
139153}
140154
141- /** @type {FromMarkdownHandle } */
155+ /**
156+ * @this {CompileContext}
157+ * @type {FromMarkdownHandle }
158+ */
142159function exitContainerLabel ( token ) {
143160 this . exit ( token )
144161}
145162
146- /** @type {FromMarkdownHandle } */
163+ /**
164+ * @this {CompileContext}
165+ * @type {FromMarkdownHandle }
166+ */
147167function enterAttributes ( ) {
168+ // @ts -expect-error: to do: register.
148169 this . setData ( 'directiveAttributes' , [ ] )
149170 this . buffer ( ) // Capture EOLs
150171}
151172
152- /** @type {FromMarkdownHandle } */
173+ /**
174+ * @this {CompileContext}
175+ * @type {FromMarkdownHandle }
176+ */
153177function exitAttributeIdValue ( token ) {
178+ // @ts -expect-error: to do: register.
154179 const list = /** @type {Array.<[string, string]> } */ (
180+ // @ts -expect-error: to do: register.
155181 this . getData ( 'directiveAttributes' )
156182 )
157183 list . push ( [
@@ -162,9 +188,14 @@ function exitAttributeIdValue(token) {
162188 ] )
163189}
164190
165- /** @type {FromMarkdownHandle } */
191+ /**
192+ * @this {CompileContext}
193+ * @type {FromMarkdownHandle }
194+ */
166195function exitAttributeClassValue ( token ) {
196+ // @ts -expect-error: to do: register.
167197 const list = /** @type {Array.<[string, string]> } */ (
198+ // @ts -expect-error: to do: register.
168199 this . getData ( 'directiveAttributes' )
169200 )
170201 list . push ( [
@@ -175,19 +206,29 @@ function exitAttributeClassValue(token) {
175206 ] )
176207}
177208
178- /** @type {FromMarkdownHandle } */
209+ /**
210+ * @this {CompileContext}
211+ * @type {FromMarkdownHandle }
212+ */
179213function exitAttributeValue ( token ) {
214+ // @ts -expect-error: to do: register.
180215 const list = /** @type {Array.<[string, string]> } */ (
216+ // @ts -expect-error: to do: register.
181217 this . getData ( 'directiveAttributes' )
182218 )
183219 list [ list . length - 1 ] [ 1 ] = parseEntities ( this . sliceSerialize ( token ) , {
184220 attribute : true
185221 } )
186222}
187223
188- /** @type {FromMarkdownHandle } */
224+ /**
225+ * @this {CompileContext}
226+ * @type {FromMarkdownHandle }
227+ */
189228function exitAttributeName ( token ) {
229+ // @ts -expect-error: to do: register.
190230 const list = /** @type {Array.<[string, string]> } */ (
231+ // @ts -expect-error: to do: register.
191232 this . getData ( 'directiveAttributes' )
192233 )
193234
@@ -196,9 +237,14 @@ function exitAttributeName(token) {
196237 list . push ( [ this . sliceSerialize ( token ) , '' ] )
197238}
198239
199- /** @type {FromMarkdownHandle } */
240+ /**
241+ * @this {CompileContext}
242+ * @type {FromMarkdownHandle }
243+ */
200244function exitAttributes ( ) {
245+ // @ts -expect-error: to do: register.
201246 const list = /** @type {Array.<[string, string]> } */ (
247+ // @ts -expect-error: to do: register.
202248 this . getData ( 'directiveAttributes' )
203249 )
204250 /** @type {Record.<string, string> } */
@@ -215,13 +261,17 @@ function exitAttributes() {
215261 }
216262 }
217263
264+ // @ts -expect-error: to do: register.
218265 this . setData ( 'directiveAttributes' )
219266 this . resume ( ) // Drop EOLs
220267 const node = /** @type {Directive } */ ( this . stack [ this . stack . length - 1 ] )
221268 node . attributes = cleaned
222269}
223270
224- /** @type {FromMarkdownHandle } */
271+ /**
272+ * @this {CompileContext}
273+ * @type {FromMarkdownHandle }
274+ */
225275function exit ( token ) {
226276 this . exit ( token )
227277}
@@ -230,10 +280,11 @@ function exit(token) {
230280 * @type {ToMarkdownHandle }
231281 * @param {Directive } node
232282 */
233- function handleDirective ( node , _ , context , safeOptions ) {
283+ function handleDirective ( node , _ , state , safeOptions ) {
234284 const tracker = track ( safeOptions )
235285 const sequence = fence ( node )
236- const exit = context . enter ( node . type )
286+ // @ts -expect-error: to do: map.
287+ const exit = state . enter ( node . type )
237288 let value = tracker . move ( sequence + ( node . name || '' ) )
238289 /** @type {Directive|Paragraph|undefined } */
239290 let label = node
@@ -244,11 +295,13 @@ function handleDirective(node, _, context, safeOptions) {
244295 }
245296
246297 if ( label && label . children && label . children . length > 0 ) {
247- const exit = context . enter ( 'label' )
248- const subexit = context . enter ( node . type + 'Label' )
298+ const exit = state . enter ( 'label' )
299+ // @ts -expect-error: to do: map.
300+ const subexit = state . enter ( node . type + 'Label' )
249301 value += tracker . move ( '[' )
250302 value += tracker . move (
251- containerPhrasing ( label , context , {
303+ // @ts -expect-error: to do: map.
304+ containerPhrasing ( label , state , {
252305 ...tracker . current ( ) ,
253306 before : value ,
254307 after : ']'
@@ -259,7 +312,7 @@ function handleDirective(node, _, context, safeOptions) {
259312 exit ( )
260313 }
261314
262- value += tracker . move ( attributes ( node , context ) )
315+ value += tracker . move ( attributes ( node , state ) )
263316
264317 if ( node . type === 'containerDirective' ) {
265318 const head = ( node . children || [ ] ) [ 0 ]
@@ -271,7 +324,7 @@ function handleDirective(node, _, context, safeOptions) {
271324
272325 if ( shallow && shallow . children && shallow . children . length > 0 ) {
273326 value += tracker . move ( '\n' )
274- value += tracker . move ( containerFlow ( shallow , context , tracker . current ( ) ) )
327+ value += tracker . move ( containerFlow ( shallow , state , tracker . current ( ) ) )
275328 }
276329
277330 value += tracker . move ( '\n' + sequence )
@@ -288,11 +341,11 @@ function peekDirective() {
288341
289342/**
290343 * @param {Directive } node
291- * @param {Context } context
344+ * @param {State } state
292345 * @returns {string }
293346 */
294- function attributes ( node , context ) {
295- const quote = checkQuote ( context )
347+ function attributes ( node , state ) {
348+ const quote = checkQuote ( state )
296349 const subset = node . type === 'textDirective' ? [ quote ] : [ quote , '\n' , '\r' ]
297350 const attrs = node . attributes || { }
298351 /** @type {Array.<string> } */
0 commit comments