From 102a9140a7202f420b04a1fba7b09025ca2e379a Mon Sep 17 00:00:00 2001 From: dreamwasp Date: Tue, 15 Oct 2024 12:55:38 -0400 Subject: [PATCH] try fix in portal --- packages/gamut/src/Markdown/index.tsx | 3 +- .../Markdown/libs/overrides/Video/index.tsx | 1 + .../src/Markdown/libs/overrides/index.tsx | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/gamut/src/Markdown/index.tsx b/packages/gamut/src/Markdown/index.tsx index e0dac07469..60d56e8648 100644 --- a/packages/gamut/src/Markdown/index.tsx +++ b/packages/gamut/src/Markdown/index.tsx @@ -10,6 +10,7 @@ import { createCodeBlockOverride, createInputOverride, createTagOverride, + createVideoOverride, MarkdownOverrideSettings, standardOverrides, } from './libs/overrides'; @@ -117,7 +118,7 @@ export class Markdown extends PureComponent { allowedAttributes: ['style'], }), !skipDefaultOverrides.video && - createTagOverride('video', { + createVideoOverride('video', { component: MarkdownVideo, }), !skipDefaultOverrides.details && diff --git a/packages/gamut/src/Markdown/libs/overrides/Video/index.tsx b/packages/gamut/src/Markdown/libs/overrides/Video/index.tsx index 95ca49f80b..63a5cdf6dc 100644 --- a/packages/gamut/src/Markdown/libs/overrides/Video/index.tsx +++ b/packages/gamut/src/Markdown/libs/overrides/Video/index.tsx @@ -20,6 +20,7 @@ export const MarkdownVideo: React.FC = (props) => { muted: props?.muted, videoTitle: props?.title, videoUrl: props?.src, + style: props?.style, width: Number(props?.width), }; diff --git a/packages/gamut/src/Markdown/libs/overrides/index.tsx b/packages/gamut/src/Markdown/libs/overrides/index.tsx index 2344557697..3ecb44fb5a 100644 --- a/packages/gamut/src/Markdown/libs/overrides/index.tsx +++ b/packages/gamut/src/Markdown/libs/overrides/index.tsx @@ -114,6 +114,43 @@ export const createTagOverride = ( }, }); +// generic video tag override +export const createVideoOverride = ( + tagName: string, + Override: MarkdownOverrideSetting +) => ({ + shouldProcessNode(node: HTMLToReactNode) { + if (!Override || node?.attribs?.src) return false; + + if (Override.shouldProcessNode) { + return Override.shouldProcessNode(node); + } + + return node.name === tagName.toLowerCase(); + }, + processNode( + node: HTMLToReactNode, + children: HTMLToReactNode[], + key: React.Key + ) { + if (!Override) return null; + + const props = { + ...processAttributes(node.attribs), + children, + key, + }; + + if (Override.processNode) { + return Override.processNode(node, props); + } + + if (!Override.component) return null; + + return ; + }, +}); + // Allows override and overrides of standard fenced codeblocks export const createCodeBlockOverride = ( tagName: string,