@@ -53,7 +53,17 @@ const ELEMENT_TAGS: IHtmlToJsonElementTags = {
53
53
TR : ( el : HTMLElement ) => ( { type : 'tr' , attrs : { } } ) ,
54
54
TD : ( el : HTMLElement ) => ( { type : 'td' , attrs : { } } ) ,
55
55
TH : ( el : HTMLElement ) => ( { type : 'th' , attrs : { } } ) ,
56
- FIGURE : ( el : HTMLElement ) => ( { type : 'reference' , attrs : { default : true , "display-type" : "display" , "type" : "asset" } } ) ,
56
+ // FIGURE: (el: HTMLElement) => ({ type: 'reference', attrs: { default: true, "display-type": "display", "type": "asset" } }),
57
+
58
+ FIGURE : ( el : HTMLElement ) => {
59
+ if ( el . lastChild && el . lastChild . nodeName === 'P' ) {
60
+ return { type : 'figure' , attrs : { } }
61
+ }
62
+ else {
63
+ return { type : 'img' , attrs : { } }
64
+ }
65
+
66
+ }
57
67
SPAN : ( el : HTMLElement ) = > {
58
68
return { type : 'span' , attrs : { } }
59
69
} ,
@@ -390,7 +400,7 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
390
400
const attrs = {
391
401
type : 'grid-container' ,
392
402
attrs : {
393
- gutter
403
+ gutter
394
404
}
395
405
}
396
406
return jsx ( 'element' , attrs , children )
@@ -514,9 +524,22 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
514
524
}
515
525
}
516
526
let captionElements = el . getElementsByTagName ( "FIGCAPTION" )
517
- if ( captionElements ?. [ 0 ] ?. textContent ) {
518
- extraAttrs [ 'asset-caption' ] = captionElements ?. [ 0 ] ?. textContent
527
+
528
+ if ( captionElements ?. [ 0 ] ) {
529
+ let caption = captionElements [ 0 ]
530
+ const captionElementsAttrs = caption . attributes
531
+ const captionAttrs = { }
532
+ if ( captionElementsAttrs ) {
533
+ Array . from ( captionElementsAttrs ) . forEach ( ( child : any ) => {
534
+ captionAttrs [ child . nodeName ] = child . nodeValue
535
+ } )
536
+ }
537
+ extraAttrs [ 'captionAttrs' ] = captionAttrs
538
+ extraAttrs [ 'caption' ] = captionElements ?. [ 0 ] ?. textContent
539
+ console . log ( extraAttrs ) ;
540
+
519
541
}
542
+
520
543
if ( newChildren [ 0 ] ?. type === 'a' ) {
521
544
const { link, target } = newChildren [ 0 ] . attrs ?. [ "redactor-attributes" ]
522
545
extraAttrs [ 'link' ] = link
0 commit comments