Skip to content

Commit b35fc20

Browse files
committed
feat: add support for social embeds
1 parent db04bfe commit b35fc20

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/fromRedactor.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ export const ELEMENT_TAGS: IHtmlToJsonElementTags = {
6060
P: () => ({ type: 'p', attrs: {} }),
6161
PRE: () => ({ type: 'code', attrs: {} }),
6262
UL: () => ({ type: 'ul', attrs: {} }),
63-
IFRAME: (el: HTMLElement) => ({ type: 'embed', attrs: { src: el.getAttribute('src') } }),
63+
IFRAME: (el: HTMLElement) => {
64+
if(el.getAttribute('data-type') === "social-embeds") {
65+
const src = el.getAttribute('src')
66+
el.removeAttribute('data-type')
67+
el.removeAttribute('src')
68+
return { type: 'social-embeds', attrs: { src } }
69+
}
70+
return { type: 'embed', attrs: { src: el.getAttribute('src') } }
71+
},
6472
TABLE: (el: HTMLElement) => ({ type: 'table', attrs: {} }),
6573
THEAD: (el: HTMLElement) => ({ type: 'thead', attrs: {} }),
6674
TBODY: (el: HTMLElement) => ({ type: 'tbody', attrs: {} }),

src/toRedactor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ const ELEMENT_TYPES: IJsonToHtmlElementTags = {
185185
},
186186
script: (attrs: any, child: any) => {
187187
return `<script ${attrs}>${child}</script>`
188+
},
189+
"social-embeds": (attrs: any, child: any) => {
190+
return `<iframe${attrs} data-type="social-embeds" ></iframe>`
188191
}
189192
}
190193
const TEXT_WRAPPERS: IJsonToHtmlTextTags = {

0 commit comments

Comments
 (0)