Skip to content

Commit 9c5f5bd

Browse files
committed
chore: convert type video to embed
1 parent 8c0a7b1 commit 9c5f5bd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/fromRedactor.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ const ELEMENT_TAGS: IHtmlToJsonElementTags = {
7070
DIV: (el: HTMLElement) => {
7171
return { type: 'div', attrs: {} }
7272
},
73+
VIDEO: (el: HTMLElement) => {
74+
const srcArray = Array.from(el.querySelectorAll("source")).map((source) =>
75+
source.getAttribute("src")
76+
);
77+
78+
return {
79+
type: 'embed',
80+
attrs: {
81+
src: srcArray.length > 0 ? srcArray[0] : null,
82+
},
83+
}
84+
},
7385
STYLE: (el: HTMLElement) => {
7486
return { type: 'style', attrs: { "style-text": el.textContent } }
7587
},
@@ -381,6 +393,9 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
381393
if (nodeName === 'FIGCAPTION') {
382394
return null
383395
}
396+
if (nodeName === 'SOURCE') {
397+
return null;
398+
}
384399
if (nodeName === 'DIV') {
385400
const dataType = el.attributes['data-type']?.value
386401
if (dataType === 'row') {
@@ -588,7 +603,7 @@ export const fromRedactor = (el: any, options?:IHtmlToJsonOptions) : IAnyObject
588603
return jsx('element', elementAttrs, [{ text: '' }])
589604
}
590605
}
591-
if (nodeName === 'IMG' || nodeName === 'IFRAME') {
606+
if (nodeName === 'IMG' || nodeName === 'IFRAME' || nodeName === 'VIDEO') {
592607
if (elementAttrs?.attrs?.["redactor-attributes"]?.width) {
593608
let width = elementAttrs.attrs["redactor-attributes"].width
594609
if (width.slice(width.length - 1) === '%') {

0 commit comments

Comments
 (0)