Skip to content

Commit fdbcf01

Browse files
committed
feat: support for figure with image as first child
1 parent ed0a57b commit fdbcf01

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/fromRedactor.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const ELEMENT_TAGS: IHtmlToJsonElementTags = {
6363
return { type: 'img', attrs: {} }
6464
}
6565

66-
}
66+
},
6767
SPAN: (el: HTMLElement) => {
6868
return { type: 'span', attrs: {} }
6969
},
@@ -536,10 +536,19 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
536536
}
537537
extraAttrs['captionAttrs'] = captionAttrs
538538
extraAttrs['caption'] = captionElements?.[0]?.textContent
539-
console.log(extraAttrs);
539+
// console.log(extraAttrs);
540540

541541
}
542-
542+
if (newChildren[0]?.type === 'img') {
543+
if (newChildren[0].attrs.width) {
544+
sizeAttrs.width = newChildren[0].attrs.width.toString()
545+
}
546+
elementAttrs = getImageAttributes(
547+
elementAttrs,
548+
{ ...newChildren[0].attrs, ...sizeAttrs },
549+
{ ...extraAttrs, ...sizeAttrs }
550+
)
551+
}
543552
if (newChildren[0]?.type === 'a') {
544553
const { link, target } = newChildren[0].attrs?.["redactor-attributes"]
545554
extraAttrs['link'] = link

0 commit comments

Comments
 (0)