Skip to content

Commit ed0a57b

Browse files
committed
feat: debugging for caption
1 parent 4941c1d commit ed0a57b

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/fromRedactor.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ const ELEMENT_TAGS: IHtmlToJsonElementTags = {
5353
TR: (el: HTMLElement) => ({ type: 'tr', attrs: {} }),
5454
TD: (el: HTMLElement) => ({ type: 'td', attrs: {} }),
5555
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+
}
5767
SPAN: (el: HTMLElement) => {
5868
return { type: 'span', attrs: {} }
5969
},
@@ -390,7 +400,7 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
390400
const attrs = {
391401
type: 'grid-container',
392402
attrs: {
393-
gutter
403+
gutter
394404
}
395405
}
396406
return jsx('element', attrs, children)
@@ -514,9 +524,22 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
514524
}
515525
}
516526
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+
519541
}
542+
520543
if (newChildren[0]?.type === 'a') {
521544
const { link, target } = newChildren[0].attrs?.["redactor-attributes"]
522545
extraAttrs['link'] = link

0 commit comments

Comments
 (0)