@@ -510,17 +510,21 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
510
510
sizeAttrs . width = el . style . width
511
511
if ( sizeAttrs . width [ sizeAttrs . width . length - 1 ] === '%' ) {
512
512
sizeAttrs . width = Number ( sizeAttrs . width . slice ( 0 , sizeAttrs . width . length - 1 ) )
513
- } else if ( sizeAttrs . width . slice ( sizeAttrs . width . length - 2 ) === 'px' ) {
514
- sizeAttrs . width = ( Number ( sizeAttrs . width . slice ( 0 , sizeAttrs . width . length - 2 ) ) / window ?. screen ?. width || 1920 ) * 100
513
+ }
514
+
515
+ else if ( sizeAttrs . width . slice ( sizeAttrs . width . length - 2 ) === 'px' ) {
516
+ sizeAttrs . width = ( Number ( sizeAttrs . width . slice ( 0 , sizeAttrs . width . length - 2 ) ) / 1920 ) * 100
515
517
}
516
518
}
517
519
if ( el . style ?. [ 'max-width' ] ) {
518
520
sizeAttrs [ 'max-width' ] = el . style [ 'max-width' ]
519
521
if ( sizeAttrs [ 'max-width' ] [ sizeAttrs [ 'max-width' ] . length - 1 ] === '%' ) {
520
522
sizeAttrs [ 'max-width' ] = Number ( sizeAttrs [ 'max-width' ] . slice ( 0 , sizeAttrs [ 'max-width' ] . length - 1 ) )
521
- } else if ( sizeAttrs [ 'max-width' ] . slice ( sizeAttrs [ 'max-width' ] . length - 2 ) === 'px' ) {
523
+ }
524
+
525
+ else if ( sizeAttrs [ 'max-width' ] . slice ( sizeAttrs [ 'max-width' ] . length - 2 ) === 'px' ) {
522
526
sizeAttrs [ 'max-width' ] =
523
- ( Number ( sizeAttrs [ 'max-width' ] . slice ( 0 , sizeAttrs [ 'max-width' ] . length - 2 ) ) / window ?. screen ?. width || 1920 ) * 100
527
+ ( Number ( sizeAttrs [ 'max-width' ] . slice ( 0 , sizeAttrs [ 'max-width' ] . length - 2 ) ) / 1920 ) * 100
524
528
}
525
529
}
526
530
let captionElements = el . getElementsByTagName ( "FIGCAPTION" )
@@ -536,7 +540,6 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
536
540
}
537
541
extraAttrs [ 'captionAttrs' ] = captionAttrs
538
542
extraAttrs [ 'caption' ] = captionElements ?. [ 0 ] ?. textContent
539
- // console.log(extraAttrs);
540
543
541
544
}
542
545
if ( newChildren [ 0 ] ?. type === 'img' ) {
@@ -545,9 +548,8 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
545
548
}
546
549
elementAttrs = getImageAttributes (
547
550
elementAttrs ,
548
- { ...newChildren [ 0 ] . attrs , ...sizeAttrs } ,
549
- { ...extraAttrs , ...sizeAttrs }
550
- )
551
+ { ...newChildren [ 0 ] . attrs , ...sizeAttrs , caption : extraAttrs [ 'caption' ] , style : { 'text-align' : style [ 'text-align' ] } } ,
552
+ { ...extraAttrs , ...sizeAttrs } ) ;
551
553
}
552
554
if ( newChildren [ 0 ] ?. type === 'a' ) {
553
555
const { link, target } = newChildren [ 0 ] . attrs ?. [ "redactor-attributes" ]
@@ -558,12 +560,13 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
558
560
const imageAttrs = newChildren [ 0 ] . children [ 0 ]
559
561
elementAttrs = getImageAttributes ( elementAttrs , imageAttrs . attrs || { } , { ...extraAttrs , ...sizeAttrs } )
560
562
}
561
- if ( newChildren [ 0 ] ?. type === 'reference' && newChildren [ 0 ] ?. attrs ?. default ) {
563
+ if ( newChildren [ 0 ] ?. type === 'reference' ) {
564
+ extraAttrs [ 'asset-caption' ] = extraAttrs [ 'caption' ]
562
565
elementAttrs = getImageAttributes (
563
- elementAttrs ,
564
- { ...newChildren [ 0 ] . attrs , ...sizeAttrs } ,
565
- { ...extraAttrs , ...sizeAttrs }
566
- )
566
+ elementAttrs ,
567
+ { ...newChildren [ 0 ] . attrs , ...sizeAttrs , position : extraAttrs . position , style : { 'text-align' : style [ 'text-align' ] } } ,
568
+ { ...extraAttrs , ...sizeAttrs } ) ;
569
+ elementAttrs . type = "reference"
567
570
}
568
571
return jsx ( 'element' , elementAttrs , [ { text : '' } ] )
569
572
}
0 commit comments