-
Notifications
You must be signed in to change notification settings - Fork 24
SCENARIO: Simplified Media Insertion (see #365). #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| #language: fr | ||
|
|
||
| Fonctionnalité: Insérer dans un document une vidéo | ||
| Fonctionnalité: Insérer dans un document une vidéo sur YouTube | ||
|
|
||
| Scénario: provenant de YouTube | ||
| Scénario: Reconnaissance automatique d'un lien YouTube pur | ||
|
|
||
| Soit un document dont je suis l'auteur affiché comme glose | ||
| Et une session active avec mon compte | ||
| Quand j'essaie de remplacer le contenu de la glose par : | ||
| """ | ||
|  | ||
| https://www.youtube.com/watch?v=JRXkAhMYKEc&ab_channel=ViniciusHenrique | ||
| """ | ||
| Alors le document comporte la vidéo "https://www.youtube.com/embed/JRXkAhMYKEc" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,7 @@ import CroppedImage from './CroppedImage'; | |
| import VideoComment from './VideoComment'; | ||
| import FragmentComment from './FragmentComment'; | ||
|
|
||
| function FormattedText({children, setHighlightedText, selectable, setSelectedText}) { | ||
|
|
||
| function FormattedText({ children, setHighlightedText, selectable, setSelectedText }) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please never commit format change (like spaces), it breaks "git blame" and generates unnecessary edition conflicts when rebasing branch. |
||
| const handleMouseUp = () => { | ||
| if (selectable) { | ||
| let text = window.getSelection().toString(); | ||
|
|
@@ -16,38 +15,49 @@ function FormattedText({children, setHighlightedText, selectable, setSelectedTex | |
| } | ||
| }; | ||
|
|
||
| return (<> | ||
| <ReactMarkdown | ||
| remarkPlugins={[remarkGfm, remarkDefinitionList, remarkUnwrapImages]} | ||
| components={{ | ||
| img: (x) => embedVideo(x) || CroppedImage(x), | ||
| p: (x) => VideoComment(x) | ||
| || FragmentComment({...x, setHighlightedText}) | ||
| || <p onMouseUp={handleMouseUp}>{x.children}</p>, | ||
| a: ({children, href}) => <a href={href}>{children}</a> | ||
| }} | ||
| remarkRehypeOptions={{ | ||
| handlers: defListHastHandlers | ||
| }} | ||
| > | ||
| {children} | ||
| </ReactMarkdown> | ||
| </>); | ||
| const renderLinkOrVideo = ({ children, href }) => { | ||
| const videoId = getId(href); | ||
| if (videoId) { | ||
| const embedLink = `https://www.youtube.com/embed/${videoId}`; | ||
| return <iframe width="80%" height="300" src={embedLink} style={{ border: 0 }} allowFullScreen title="YouTube video" />; | ||
| } | ||
| return <a href={href}>{children}</a>; | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please never commit format change (like line break and indentation), it breaks "git blame" and generates unnecessary edition conflicts when rebasing branch, and make code review far more long and complex. |
||
| <ReactMarkdown | ||
| remarkPlugins={[remarkGfm, remarkDefinitionList, remarkUnwrapImages]} | ||
| components={{ | ||
| img: (x) => embedVideo(x) || CroppedImage(x), | ||
| p: (x) => | ||
| VideoComment(x) || | ||
| FragmentComment({ ...x, setHighlightedText }) || | ||
| <p onMouseUp={handleMouseUp}>{x.children}</p>, | ||
| a: renderLinkOrVideo | ||
| }} | ||
| remarkRehypeOptions={{ | ||
| handlers: defListHastHandlers | ||
| }} | ||
| > | ||
| {children} | ||
| </ReactMarkdown> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| 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}) { | ||
| function embedVideo({ src }) { | ||
| const videoId = getId(src); | ||
| if (videoId) { | ||
| const embedLink = `https://www.youtube.com/embed/${videoId}`; | ||
| return ( | ||
| <iframe width="80%" height="300" src={embedLink} frameBorder="0" allowFullScreen></iframe> | ||
| ); | ||
| return <iframe width="80%" height="300" src={embedLink} style={{ border: 0 }} allowFullScreen title="YouTube video" />; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please never commit format change (like line break, parenthesis and indentation), it breaks "git blame" and generates unnecessary edition conflicts when rebasing branch, and make code review far more long and complex. |
||
| } | ||
| return null; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't change those 2 lines since we hope, one day, to be compatible also with Dailymotion, Pod, etc.