@@ -288,6 +288,62 @@ function transform(state, node) {
288
288
return text ( state , unsafe )
289
289
}
290
290
291
+ case 'mdxJsxFlowElement' : {
292
+ // Map the attributes array into name/value pairs
293
+ const attributesMap = { }
294
+ if ( Array . isArray ( unsafe . attributes ) ) {
295
+ unsafe . attributes . forEach ( ( attr ) => {
296
+ if (
297
+ attr &&
298
+ typeof attr === 'object' &&
299
+ 'name' in attr &&
300
+ 'value' in attr
301
+ ) {
302
+ attributesMap [ attr . name ] = attr . value
303
+ }
304
+ } )
305
+ }
306
+
307
+ const mdxProps = {
308
+ ...unsafe ,
309
+ tagName : unsafe . name ,
310
+ properties : {
311
+ ...unsafe . properties ,
312
+ ...attributesMap // Spread the mapped attributes directly into properties
313
+ }
314
+ }
315
+
316
+ return element ( state , mdxProps )
317
+ }
318
+
319
+ case 'mdxJsxTextElement' : {
320
+ // Handle text elements the same way
321
+ const attributesMap = { }
322
+ if ( Array . isArray ( unsafe . attributes ) ) {
323
+ unsafe . attributes . forEach ( ( attr ) => {
324
+ if (
325
+ attr &&
326
+ typeof attr === 'object' &&
327
+ 'name' in attr &&
328
+ 'value' in attr
329
+ ) {
330
+ attributesMap [ attr . name ] = attr . value
331
+ }
332
+ } )
333
+ }
334
+
335
+ const mdxProps = {
336
+ ...unsafe ,
337
+ tagName : unsafe . name ,
338
+ properties : {
339
+ ...unsafe . properties ,
340
+ ...attributesMap
341
+ }
342
+ }
343
+
344
+ return element ( state , mdxProps )
345
+ }
346
+
291
347
default :
292
348
}
293
349
}
@@ -503,15 +559,18 @@ function properties(state, properties) {
503
559
: undefined
504
560
const defaults =
505
561
attributes && own . call ( attributes , '*' ) ? attributes [ '*' ] : undefined
562
+
563
+ // Handle both traditional properties and MDX attributes
506
564
const properties_ =
507
- /** @type { Readonly<Record<string, Readonly<unknown>>> } */ (
508
- properties && typeof properties === 'object' ? properties : { }
509
- )
565
+ properties && typeof properties === 'object' ? properties : { }
566
+ const mdxAttributes = properties_ ?. attributes || { } // Add support for MDX attributes
567
+
510
568
/** @type {Properties } */
511
569
const result = { }
512
570
/** @type {string } */
513
571
let key
514
572
573
+ // Process traditional properties
515
574
for ( key in properties_ ) {
516
575
if ( own . call ( properties_ , key ) ) {
517
576
const unsafe = properties_ [ key ]
@@ -532,9 +591,30 @@ function properties(state, properties) {
532
591
}
533
592
}
534
593
594
+ // Process MDX attributes
595
+ for ( key in mdxAttributes ) {
596
+ if ( own . call ( mdxAttributes , key ) ) {
597
+ const unsafe = mdxAttributes [ key ]
598
+ let safe = propertyValue (
599
+ state ,
600
+ findDefinition ( specific , key ) ,
601
+ key ,
602
+ unsafe
603
+ )
604
+
605
+ if ( safe === null || safe === undefined ) {
606
+ safe = propertyValue ( state , findDefinition ( defaults , key ) , key , unsafe )
607
+ }
608
+
609
+ if ( safe !== null && safe !== undefined ) {
610
+ result [ key ] = safe
611
+ }
612
+ }
613
+ }
614
+
615
+ // Handle required properties
535
616
if ( required && own . call ( required , tagName ) ) {
536
617
const properties = required [ tagName ]
537
-
538
618
for ( key in properties ) {
539
619
if ( own . call ( properties , key ) && ! own . call ( result , key ) ) {
540
620
result [ key ] = properties [ key ]
0 commit comments