Skip to content

Commit 4737665

Browse files
authored
Merge pull request #6414 from remix-project-org/yann300-patch-66
Render videos in md
2 parents aaf1277 + 2a1b4de commit 4737665

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

apps/learneth/src/pages/StepDetail/index.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,40 @@ function StepDetailPage() {
7272
)
7373
}
7474

75+
const VideoRenderer = ({
76+
node,
77+
src,
78+
alt,
79+
...props
80+
}: {
81+
node?: any;
82+
src?: string;
83+
alt?: string;
84+
[key: string]: any;
85+
}) => {
86+
if (alt === 'youtube') {
87+
/*
88+
<iframe width="560" height="315" src="https://www.youtube.com/embed/Eh1qgOurDxU?si=lz1JypmIJZ15OY4g" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
89+
*/
90+
return (
91+
<div className="position-relative overflow-hidden" style={{ paddingBottom: '56.25%', maxWidth: '100%', height: '0' }}>
92+
<iframe
93+
style={{ width: '100%', height: '100%', position: 'absolute', top: 0, left: 0 }}
94+
src={src}
95+
title="YouTube video player"
96+
frameBorder="0"
97+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
98+
allowFullScreen
99+
/>
100+
</div>
101+
);
102+
}
103+
if (alt === 'video') {
104+
return <video controls src={src} style={{ maxWidth: '100%' }} />;
105+
}
106+
return <img src={src} alt={alt} {...props} />;
107+
};
108+
75109
return (
76110
<div className='pb-4'>
77111
<div className="fixed-top">
@@ -104,7 +138,7 @@ function StepDetailPage() {
104138
</>
105139
)}
106140
<div className="container-fluid">
107-
<Markdown rehypePlugins={[rehypeRaw]}>{clonedStep.markdown?.content}</Markdown>
141+
<Markdown components={{ img:VideoRenderer }} rehypePlugins={[rehypeRaw]}>{clonedStep.markdown?.content}</Markdown>
108142
</div>
109143
{clonedStep.test?.content ? (
110144
<>

0 commit comments

Comments
 (0)