7
7
* @typedef {import('mdast-util-from-markdown').CompileContext } CompileContext
8
8
* @typedef {import('mdast-util-from-markdown').Token } Token
9
9
* @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
11
11
* @typedef {import('mdast-util-to-markdown/lib/types.js').Options } ToMarkdownExtension
12
12
* @typedef {import('./complex-types').ContainerDirective } ContainerDirective
13
13
* @typedef {import('./complex-types').LeafDirective } LeafDirective
@@ -76,10 +76,12 @@ export const directiveToMarkdown = {
76
76
unsafe : [
77
77
{
78
78
character : '\r' ,
79
+ // @ts -expect-error: to do: map.
79
80
inConstruct : [ 'leafDirectiveLabel' , 'containerDirectiveLabel' ]
80
81
} ,
81
82
{
82
83
character : '\n' ,
84
+ // @ts -expect-error: to do: map.
83
85
inConstruct : [ 'leafDirectiveLabel' , 'containerDirectiveLabel' ]
84
86
} ,
85
87
{
@@ -97,17 +99,26 @@ export const directiveToMarkdown = {
97
99
}
98
100
}
99
101
100
- /** @type {FromMarkdownHandle } */
102
+ /**
103
+ * @this {CompileContext}
104
+ * @type {FromMarkdownHandle }
105
+ */
101
106
function enterContainer ( token ) {
102
107
enter . call ( this , 'containerDirective' , token )
103
108
}
104
109
105
- /** @type {FromMarkdownHandle } */
110
+ /**
111
+ * @this {CompileContext}
112
+ * @type {FromMarkdownHandle }
113
+ */
106
114
function enterLeaf ( token ) {
107
115
enter . call ( this , 'leafDirective' , token )
108
116
}
109
117
110
- /** @type {FromMarkdownHandle } */
118
+ /**
119
+ * @this {CompileContext}
120
+ * @type {FromMarkdownHandle }
121
+ */
111
122
function enterText ( token ) {
112
123
enter . call ( this , 'textDirective' , token )
113
124
}
@@ -130,28 +141,43 @@ function exitName(token) {
130
141
node . name = this . sliceSerialize ( token )
131
142
}
132
143
133
- /** @type {FromMarkdownHandle } */
144
+ /**
145
+ * @this {CompileContext}
146
+ * @type {FromMarkdownHandle }
147
+ */
134
148
function enterContainerLabel ( token ) {
135
149
this . enter (
136
150
{ type : 'paragraph' , data : { directiveLabel : true } , children : [ ] } ,
137
151
token
138
152
)
139
153
}
140
154
141
- /** @type {FromMarkdownHandle } */
155
+ /**
156
+ * @this {CompileContext}
157
+ * @type {FromMarkdownHandle }
158
+ */
142
159
function exitContainerLabel ( token ) {
143
160
this . exit ( token )
144
161
}
145
162
146
- /** @type {FromMarkdownHandle } */
163
+ /**
164
+ * @this {CompileContext}
165
+ * @type {FromMarkdownHandle }
166
+ */
147
167
function enterAttributes ( ) {
168
+ // @ts -expect-error: to do: register.
148
169
this . setData ( 'directiveAttributes' , [ ] )
149
170
this . buffer ( ) // Capture EOLs
150
171
}
151
172
152
- /** @type {FromMarkdownHandle } */
173
+ /**
174
+ * @this {CompileContext}
175
+ * @type {FromMarkdownHandle }
176
+ */
153
177
function exitAttributeIdValue ( token ) {
178
+ // @ts -expect-error: to do: register.
154
179
const list = /** @type {Array.<[string, string]> } */ (
180
+ // @ts -expect-error: to do: register.
155
181
this . getData ( 'directiveAttributes' )
156
182
)
157
183
list . push ( [
@@ -162,9 +188,14 @@ function exitAttributeIdValue(token) {
162
188
] )
163
189
}
164
190
165
- /** @type {FromMarkdownHandle } */
191
+ /**
192
+ * @this {CompileContext}
193
+ * @type {FromMarkdownHandle }
194
+ */
166
195
function exitAttributeClassValue ( token ) {
196
+ // @ts -expect-error: to do: register.
167
197
const list = /** @type {Array.<[string, string]> } */ (
198
+ // @ts -expect-error: to do: register.
168
199
this . getData ( 'directiveAttributes' )
169
200
)
170
201
list . push ( [
@@ -175,19 +206,29 @@ function exitAttributeClassValue(token) {
175
206
] )
176
207
}
177
208
178
- /** @type {FromMarkdownHandle } */
209
+ /**
210
+ * @this {CompileContext}
211
+ * @type {FromMarkdownHandle }
212
+ */
179
213
function exitAttributeValue ( token ) {
214
+ // @ts -expect-error: to do: register.
180
215
const list = /** @type {Array.<[string, string]> } */ (
216
+ // @ts -expect-error: to do: register.
181
217
this . getData ( 'directiveAttributes' )
182
218
)
183
219
list [ list . length - 1 ] [ 1 ] = parseEntities ( this . sliceSerialize ( token ) , {
184
220
attribute : true
185
221
} )
186
222
}
187
223
188
- /** @type {FromMarkdownHandle } */
224
+ /**
225
+ * @this {CompileContext}
226
+ * @type {FromMarkdownHandle }
227
+ */
189
228
function exitAttributeName ( token ) {
229
+ // @ts -expect-error: to do: register.
190
230
const list = /** @type {Array.<[string, string]> } */ (
231
+ // @ts -expect-error: to do: register.
191
232
this . getData ( 'directiveAttributes' )
192
233
)
193
234
@@ -196,9 +237,14 @@ function exitAttributeName(token) {
196
237
list . push ( [ this . sliceSerialize ( token ) , '' ] )
197
238
}
198
239
199
- /** @type {FromMarkdownHandle } */
240
+ /**
241
+ * @this {CompileContext}
242
+ * @type {FromMarkdownHandle }
243
+ */
200
244
function exitAttributes ( ) {
245
+ // @ts -expect-error: to do: register.
201
246
const list = /** @type {Array.<[string, string]> } */ (
247
+ // @ts -expect-error: to do: register.
202
248
this . getData ( 'directiveAttributes' )
203
249
)
204
250
/** @type {Record.<string, string> } */
@@ -215,13 +261,17 @@ function exitAttributes() {
215
261
}
216
262
}
217
263
264
+ // @ts -expect-error: to do: register.
218
265
this . setData ( 'directiveAttributes' )
219
266
this . resume ( ) // Drop EOLs
220
267
const node = /** @type {Directive } */ ( this . stack [ this . stack . length - 1 ] )
221
268
node . attributes = cleaned
222
269
}
223
270
224
- /** @type {FromMarkdownHandle } */
271
+ /**
272
+ * @this {CompileContext}
273
+ * @type {FromMarkdownHandle }
274
+ */
225
275
function exit ( token ) {
226
276
this . exit ( token )
227
277
}
@@ -230,10 +280,11 @@ function exit(token) {
230
280
* @type {ToMarkdownHandle }
231
281
* @param {Directive } node
232
282
*/
233
- function handleDirective ( node , _ , context , safeOptions ) {
283
+ function handleDirective ( node , _ , state , safeOptions ) {
234
284
const tracker = track ( safeOptions )
235
285
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 )
237
288
let value = tracker . move ( sequence + ( node . name || '' ) )
238
289
/** @type {Directive|Paragraph|undefined } */
239
290
let label = node
@@ -244,11 +295,13 @@ function handleDirective(node, _, context, safeOptions) {
244
295
}
245
296
246
297
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' )
249
301
value += tracker . move ( '[' )
250
302
value += tracker . move (
251
- containerPhrasing ( label , context , {
303
+ // @ts -expect-error: to do: map.
304
+ containerPhrasing ( label , state , {
252
305
...tracker . current ( ) ,
253
306
before : value ,
254
307
after : ']'
@@ -259,7 +312,7 @@ function handleDirective(node, _, context, safeOptions) {
259
312
exit ( )
260
313
}
261
314
262
- value += tracker . move ( attributes ( node , context ) )
315
+ value += tracker . move ( attributes ( node , state ) )
263
316
264
317
if ( node . type === 'containerDirective' ) {
265
318
const head = ( node . children || [ ] ) [ 0 ]
@@ -271,7 +324,7 @@ function handleDirective(node, _, context, safeOptions) {
271
324
272
325
if ( shallow && shallow . children && shallow . children . length > 0 ) {
273
326
value += tracker . move ( '\n' )
274
- value += tracker . move ( containerFlow ( shallow , context , tracker . current ( ) ) )
327
+ value += tracker . move ( containerFlow ( shallow , state , tracker . current ( ) ) )
275
328
}
276
329
277
330
value += tracker . move ( '\n' + sequence )
@@ -288,11 +341,11 @@ function peekDirective() {
288
341
289
342
/**
290
343
* @param {Directive } node
291
- * @param {Context } context
344
+ * @param {State } state
292
345
* @returns {string }
293
346
*/
294
- function attributes ( node , context ) {
295
- const quote = checkQuote ( context )
347
+ function attributes ( node , state ) {
348
+ const quote = checkQuote ( state )
296
349
const subset = node . type === 'textDirective' ? [ quote ] : [ quote , '\n' , '\r' ]
297
350
const attrs = node . attributes || { }
298
351
/** @type {Array.<string> } */
0 commit comments