Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/scenarios/include_video.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Scénario: provenant de YouTube
Et une session active avec mon compte
Quand j'essaie de remplacer le contenu de la glose par :
"""
![link](https://www.youtube.com/watch?v=JRXkAhMYKEc&ab_channel=ViniciusHenrique)
https://www.youtube.com/watch?v=JRXkAhMYKEc&ab_channel=ViniciusHenrique
"""
Alors le document comporte la vidéo "https://www.youtube.com/embed/JRXkAhMYKEc"

11 changes: 7 additions & 4 deletions frontend/src/components/FormattedText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ function FormattedText({children, setHighlightedText, selectable, setSelectedTex
}
};

const AutoLink = ({children, href}) => <a href={href}>{children}</a>;

return (<>
<ReactMarkdown
remarkPlugins={[remarkGfm, remarkDefinitionList, remarkUnwrapImages]}
components={{
img: (x) => embedVideo(x) || CroppedImage(x),
img: (x) => Video(x) || CroppedImage(x),
p: (x) => VideoComment(x)
|| FragmentComment({...x, setHighlightedText})
|| <p onMouseUp={handleMouseUp}>{x.children}</p>,
a: ({children, href}) => <a href={href}>{children}</a>
a: (x) => Video(x) || AutoLink(x)
}}
remarkRehypeOptions={{
handlers: defListHastHandlers
Expand All @@ -36,13 +38,14 @@ function FormattedText({children, setHighlightedText, selectable, setSelectedTex
}

function getId(text) {
if (!text) return null;
const regExp = /^.*(?:youtube\.com\/watch\?v=|youtu\.be\/)([^\s&]{11})/;
const match = text.match(regExp);
return match ? match[1] : null;
}

function embedVideo({src}) {
const videoId = getId(src);
function Video({src, href}) {
const videoId = getId(src || href);
if (videoId) {
const embedLink = `https://www.youtube.com/embed/${videoId}`;
return (
Expand Down
Loading