Skip to content

Commit

Permalink
SUL23-377 Fix wysiwyg video embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 14, 2023
1 parent 4d340eb commit 4e0f68f
Show file tree
Hide file tree
Showing 2 changed files with 995 additions and 1,003 deletions.
17 changes: 14 additions & 3 deletions lib/format-html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,27 @@ const fixClasses = (classes) => {
}

const cleanMediaMarkup = (node: Element) => {

const findIframeInMedia = (item: Element) => {
const iframe = item.children.find(child => child instanceof Element && child.name === 'iframe')
if (iframe) return iframe;
for (let i = 0; i <= item.children.length; i++) {
const childIframe = findIframeInMedia(item.children[i])
if (childIframe) return childIframe;
}
}

const wrapperDiv = node.children.find(child => child instanceof Element && child.name === 'div')
const picture = wrapperDiv instanceof Element && wrapperDiv.children.find(child => child instanceof Element && child.name === 'picture')
let image = wrapperDiv instanceof Element && wrapperDiv.children.find(child => child instanceof Element && child.name === 'img')

// Special handling of video media type.
if (node.attribs.class.indexOf('media--type-video') >= 0) {
const iframe = wrapperDiv instanceof Element && wrapperDiv.children.find(child => child instanceof Element && child.name === 'iframe')
// @ts-ignore
let {src: iframeSrc} = iframe instanceof Element && iframe.attribs;
// const iframe = wrapperDiv instanceof Element && wrapperDiv.children.find(child => child instanceof Element && child.name === 'iframe')
const iframe = findIframeInMedia(node);

// @ts-ignore
let {"data-src": iframeSrc} = iframe && iframe.attribs;
iframeSrc = decodeURIComponent(iframeSrc).replace(/^.*url=(.*)?&.*$/, '$1');
return (
<div className="su-clear-both su-overflow-hidden su-aspect-[16/9] su-relative">
Expand Down
Loading

1 comment on commit 4e0f68f

@vercel
Copy link

@vercel vercel bot commented on 4e0f68f Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.