Skip to content

Commit

Permalink
feat: add support for social embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayesh2812 committed Oct 18, 2024
1 parent db04bfe commit b35fc20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/fromRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ export const ELEMENT_TAGS: IHtmlToJsonElementTags = {
P: () => ({ type: 'p', attrs: {} }),
PRE: () => ({ type: 'code', attrs: {} }),
UL: () => ({ type: 'ul', attrs: {} }),
IFRAME: (el: HTMLElement) => ({ type: 'embed', attrs: { src: el.getAttribute('src') } }),
IFRAME: (el: HTMLElement) => {
if(el.getAttribute('data-type') === "social-embeds") {
const src = el.getAttribute('src')
el.removeAttribute('data-type')
el.removeAttribute('src')
return { type: 'social-embeds', attrs: { src } }
}
return { type: 'embed', attrs: { src: el.getAttribute('src') } }
},
TABLE: (el: HTMLElement) => ({ type: 'table', attrs: {} }),
THEAD: (el: HTMLElement) => ({ type: 'thead', attrs: {} }),
TBODY: (el: HTMLElement) => ({ type: 'tbody', attrs: {} }),
Expand Down
3 changes: 3 additions & 0 deletions src/toRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ const ELEMENT_TYPES: IJsonToHtmlElementTags = {
},
script: (attrs: any, child: any) => {
return `<script ${attrs}>${child}</script>`
},
"social-embeds": (attrs: any, child: any) => {
return `<iframe${attrs} data-type="social-embeds" ></iframe>`
}
}
const TEXT_WRAPPERS: IJsonToHtmlTextTags = {
Expand Down

0 comments on commit b35fc20

Please sign in to comment.