Skip to content

Commit 387a672

Browse files
authored
render videos in md
1 parent 7380e94 commit 387a672

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,39 @@ 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+
<iframe
92+
/*width="560"
93+
height="315"*/
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+
);
101+
}
102+
if (alt === 'video') {
103+
return <video controls src={src} style={{ maxWidth: '100%' }} />;
104+
}
105+
return <img src={src} alt={alt} {...props} />;
106+
};
107+
75108
return (
76109
<div className='pb-4'>
77110
<div className="fixed-top">
@@ -104,7 +137,9 @@ function StepDetailPage() {
104137
</>
105138
)}
106139
<div className="container-fluid">
107-
<Markdown rehypePlugins={[rehypeRaw]}>{clonedStep.markdown?.content}</Markdown>
140+
<Markdown components={{
141+
img: VideoRenderer
142+
}} rehypePlugins={[rehypeRaw]}>{clonedStep.markdown?.content}</Markdown>
108143
</div>
109144
{clonedStep.test?.content ? (
110145
<>

0 commit comments

Comments
 (0)