@@ -60,9 +60,6 @@ import {parseEntities} from 'parse-entities'
60
60
import { stringifyPosition } from 'unist-util-stringify-position'
61
61
import { VFileMessage } from 'vfile-message'
62
62
import { stringifyEntitiesLight } from 'stringify-entities'
63
- import { containerPhrasing } from 'mdast-util-to-markdown/lib/util/container-phrasing.js'
64
- import { indentLines } from 'mdast-util-to-markdown/lib/util/indent-lines.js'
65
- import { track } from 'mdast-util-to-markdown/lib/util/track.js'
66
63
67
64
// To do: next major: use `state`, use utilities from state, rename `safeOptions` to `info`.
68
65
@@ -163,8 +160,8 @@ export function mdxJsxFromMarkdown() {
163
160
start : token . start ,
164
161
end : token . end
165
162
}
166
- if ( ! this . getData ( ' mdxJsxTagStack' ) ) this . setData ( ' mdxJsxTagStack' , [ ] )
167
- this . setData ( ' mdxJsxTag' , tag )
163
+ if ( ! this . data . mdxJsxTagStack ) this . data . mdxJsxTagStack = [ ]
164
+ this . data . mdxJsxTag = tag
168
165
this . buffer ( )
169
166
}
170
167
@@ -173,7 +170,7 @@ export function mdxJsxFromMarkdown() {
173
170
* @type {FromMarkdownHandle }
174
171
*/
175
172
function enterMdxJsxTagClosingMarker ( token ) {
176
- const stack = /** @type {Array<Tag> } */ ( this . getData ( ' mdxJsxTagStack' ) )
173
+ const stack = /** @type {Array<Tag> } */ ( this . data . mdxJsxTagStack )
177
174
178
175
if ( stack . length === 0 ) {
179
176
throw new VFileMessage (
@@ -189,7 +186,7 @@ export function mdxJsxFromMarkdown() {
189
186
* @type {FromMarkdownHandle }
190
187
*/
191
188
function enterMdxJsxTagAnyAttribute ( token ) {
192
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
189
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
193
190
194
191
if ( tag . close ) {
195
192
throw new VFileMessage (
@@ -205,7 +202,7 @@ export function mdxJsxFromMarkdown() {
205
202
* @type {FromMarkdownHandle }
206
203
*/
207
204
function enterMdxJsxTagSelfClosingMarker ( token ) {
208
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
205
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
209
206
210
207
if ( tag . close ) {
211
208
throw new VFileMessage (
@@ -221,7 +218,7 @@ export function mdxJsxFromMarkdown() {
221
218
* @type {FromMarkdownHandle }
222
219
*/
223
220
function exitMdxJsxTagClosingMarker ( ) {
224
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
221
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
225
222
tag . close = true
226
223
}
227
224
@@ -230,7 +227,7 @@ export function mdxJsxFromMarkdown() {
230
227
* @type {FromMarkdownHandle }
231
228
*/
232
229
function exitMdxJsxTagNamePrimary ( token ) {
233
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
230
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
234
231
tag . name = this . sliceSerialize ( token )
235
232
}
236
233
@@ -239,7 +236,7 @@ export function mdxJsxFromMarkdown() {
239
236
* @type {FromMarkdownHandle }
240
237
*/
241
238
function exitMdxJsxTagNameMember ( token ) {
242
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
239
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
243
240
tag . name += '.' + this . sliceSerialize ( token )
244
241
}
245
242
@@ -248,7 +245,7 @@ export function mdxJsxFromMarkdown() {
248
245
* @type {FromMarkdownHandle }
249
246
*/
250
247
function exitMdxJsxTagNameLocal ( token ) {
251
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
248
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
252
249
tag . name += ':' + this . sliceSerialize ( token )
253
250
}
254
251
@@ -257,7 +254,7 @@ export function mdxJsxFromMarkdown() {
257
254
* @type {FromMarkdownHandle }
258
255
*/
259
256
function enterMdxJsxTagAttribute ( token ) {
260
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
257
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
261
258
enterMdxJsxTagAnyAttribute . call ( this , token )
262
259
tag . attributes . push ( { type : 'mdxJsxAttribute' , name : '' , value : null } )
263
260
}
@@ -267,7 +264,7 @@ export function mdxJsxFromMarkdown() {
267
264
* @type {FromMarkdownHandle }
268
265
*/
269
266
function enterMdxJsxTagExpressionAttribute ( token ) {
270
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
267
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
271
268
enterMdxJsxTagAnyAttribute . call ( this , token )
272
269
tag . attributes . push ( { type : 'mdxJsxExpressionAttribute' , value : '' } )
273
270
this . buffer ( )
@@ -278,7 +275,7 @@ export function mdxJsxFromMarkdown() {
278
275
* @type {FromMarkdownHandle }
279
276
*/
280
277
function exitMdxJsxTagExpressionAttribute ( token ) {
281
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
278
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
282
279
const tail = /** @type {MdxJsxExpressionAttribute } */ (
283
280
tag . attributes [ tag . attributes . length - 1 ]
284
281
)
@@ -296,7 +293,7 @@ export function mdxJsxFromMarkdown() {
296
293
* @type {FromMarkdownHandle }
297
294
*/
298
295
function exitMdxJsxTagAttributeNamePrimary ( token ) {
299
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
296
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
300
297
const node = /** @type {MdxJsxAttribute } */ (
301
298
tag . attributes [ tag . attributes . length - 1 ]
302
299
)
@@ -308,7 +305,7 @@ export function mdxJsxFromMarkdown() {
308
305
* @type {FromMarkdownHandle }
309
306
*/
310
307
function exitMdxJsxTagAttributeNameLocal ( token ) {
311
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
308
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
312
309
const node = /** @type {MdxJsxAttribute } */ (
313
310
tag . attributes [ tag . attributes . length - 1 ]
314
311
)
@@ -320,7 +317,7 @@ export function mdxJsxFromMarkdown() {
320
317
* @type {FromMarkdownHandle }
321
318
*/
322
319
function exitMdxJsxTagAttributeValueLiteral ( ) {
323
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
320
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
324
321
tag . attributes [ tag . attributes . length - 1 ] . value = parseEntities (
325
322
this . resume ( ) ,
326
323
{ nonTerminated : false }
@@ -332,7 +329,7 @@ export function mdxJsxFromMarkdown() {
332
329
* @type {FromMarkdownHandle }
333
330
*/
334
331
function exitMdxJsxTagAttributeValueExpression ( token ) {
335
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
332
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
336
333
const tail = /** @type {MdxJsxAttribute } */ (
337
334
tag . attributes [ tag . attributes . length - 1 ]
338
335
)
@@ -352,7 +349,7 @@ export function mdxJsxFromMarkdown() {
352
349
* @type {FromMarkdownHandle }
353
350
*/
354
351
function exitMdxJsxTagSelfClosingMarker ( ) {
355
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
352
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
356
353
357
354
tag . selfClosing = true
358
355
}
@@ -362,8 +359,8 @@ export function mdxJsxFromMarkdown() {
362
359
* @type {FromMarkdownHandle }
363
360
*/
364
361
function exitMdxJsxTag ( token ) {
365
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
366
- const stack = /** @type {Array<Tag> } */ ( this . getData ( ' mdxJsxTagStack' ) )
362
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
363
+ const stack = /** @type {Array<Tag> } */ ( this . data . mdxJsxTagStack )
367
364
const tail = stack [ stack . length - 1 ]
368
365
369
366
if ( tag . close && tail . name !== tag . name ) {
@@ -413,7 +410,7 @@ export function mdxJsxFromMarkdown() {
413
410
* @type {OnEnterError }
414
411
*/
415
412
function onErrorRightIsTag ( closing , open ) {
416
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
413
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
417
414
const place = closing ? ' before the end of `' + closing . type + '`' : ''
418
415
const position = closing
419
416
? { start : closing . start , end : closing . end }
@@ -436,7 +433,7 @@ export function mdxJsxFromMarkdown() {
436
433
* @type {OnExitError }
437
434
*/
438
435
function onErrorLeftIsTag ( a , b ) {
439
- const tag = /** @type {Tag } */ ( this . getData ( ' mdxJsxTag' ) )
436
+ const tag = /** @type {Tag } */ ( this . data . mdxJsxTag )
440
437
throw new VFileMessage (
441
438
'Expected the closing tag `' +
442
439
serializeAbbreviatedTag ( tag ) +
@@ -523,8 +520,8 @@ export function mdxJsxToMarkdown(options) {
523
520
: false
524
521
const depth = inferDepth ( context )
525
522
const currentIndent = createIndent ( depth )
526
- const trackerOneLine = track ( safeOptions )
527
- const trackerMultiLine = track ( safeOptions )
523
+ const trackerOneLine = context . createTracker ( safeOptions )
524
+ const trackerMultiLine = context . createTracker ( safeOptions )
528
525
/** @type {Array<string> } */
529
526
const serializedAttributes = [ ]
530
527
const prefix = ( flow ? currentIndent : '' ) + '<' + ( node . name || '' )
@@ -633,7 +630,11 @@ export function mdxJsxToMarkdown(options) {
633
630
if ( node . children && node . children . length > 0 ) {
634
631
if ( node . type === 'mdxJsxTextElement' ) {
635
632
value += tracker . move (
636
- containerPhrasing ( node , context , {
633
+ // @ts -expect-error: `containerPhrasing` is typed correctly, but TS
634
+ // generates *hardcoded* types, which means that our dynamically added
635
+ // directives are not present.
636
+ // At some point, TS should fix that, and `from-markdown` should be fine.
637
+ context . containerPhrasing ( node , {
637
638
...tracker . current ( ) ,
638
639
before : '>' ,
639
640
after : '<'
@@ -697,7 +698,7 @@ function containerFlow(parent, state, info) {
697
698
const serializedChild =
698
699
child . type === 'mdxJsxFlowElement'
699
700
? result
700
- : indentLines ( result , function ( line , _ , blank ) {
701
+ : state . indentLines ( result , function ( line , _ , blank ) {
701
702
return ( blank ? '' : currentIndent ) + line
702
703
} )
703
704
0 commit comments