Commit 8c9a9c45 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '332074-render-video-in-content-editor' into 'master'

Render video in content editor

See merge request gitlab-org/gitlab!69169
parents b8e1b300 7fedc5e0
/* eslint-disable class-methods-use-this */ /* eslint-disable class-methods-use-this */
/* eslint-disable @gitlab/require-i18n-strings */
import { defaultMarkdownSerializer } from 'prosemirror-markdown'; import { defaultMarkdownSerializer } from 'prosemirror-markdown';
import { Node } from 'tiptap'; import { Node } from 'tiptap';
...@@ -30,19 +31,19 @@ export default class Playable extends Node { ...@@ -30,19 +31,19 @@ export default class Playable extends Node {
const parseDOM = [ const parseDOM = [
{ {
tag: `.media-container`, tag: `.${this.mediaType}-container`,
getAttrs: (el) => ({ getAttrs: (el) => ({
src: el.querySelector('audio,video').src, src: el.querySelector(this.mediaType).src,
alt: el.querySelector('audio,video').dataset.title, alt: el.querySelector(this.mediaType).dataset.title,
}), }),
}, },
]; ];
const toDOM = (node) => [ const toDOM = (node) => [
'span', 'span',
{ class: 'media-container' }, { class: `media-container ${this.mediaType}-container` },
[ [
this.options.mediaType, this.mediaType,
{ {
src: node.attrs.src, src: node.attrs.src,
controls: true, controls: true,
......
import Playable from './playable'; import Playable from './playable';
export default Playable.extend({ export default Playable.extend({
name: 'audio',
defaultOptions: { defaultOptions: {
...Playable.options, ...Playable.options,
mediaType: 'audio', mediaType: 'audio',
......
/* eslint-disable @gitlab/require-i18n-strings */
import { Node } from '@tiptap/core'; import { Node } from '@tiptap/core';
const queryPlayableElement = (element, mediaType) => element.querySelector(mediaType); const queryPlayableElement = (element, mediaType) => element.querySelector(mediaType);
export default Node.create({ export default Node.create({
name: 'playable',
group: 'inline', group: 'inline',
inline: true, inline: true,
draggable: true, draggable: true,
...@@ -46,7 +47,7 @@ export default Node.create({ ...@@ -46,7 +47,7 @@ export default Node.create({
parseHTML() { parseHTML() {
return [ return [
{ {
tag: '.media-container', tag: `.${this.options.mediaType}-container`,
}, },
]; ];
}, },
...@@ -54,7 +55,7 @@ export default Node.create({ ...@@ -54,7 +55,7 @@ export default Node.create({
renderHTML({ node }) { renderHTML({ node }) {
return [ return [
'span', 'span',
{ class: 'media-container' }, { class: `media-container ${this.options.mediaType}-container` },
[ [
this.options.mediaType, this.options.mediaType,
{ {
......
import Playable from './playable';
export default Playable.extend({
name: 'video',
defaultOptions: {
...Playable.options,
mediaType: 'video',
extraElementAttrs: { width: '400' },
},
});
...@@ -39,6 +39,7 @@ import TableRow from '../extensions/table_row'; ...@@ -39,6 +39,7 @@ import TableRow from '../extensions/table_row';
import TaskItem from '../extensions/task_item'; import TaskItem from '../extensions/task_item';
import TaskList from '../extensions/task_list'; import TaskList from '../extensions/task_list';
import Text from '../extensions/text'; import Text from '../extensions/text';
import Video from '../extensions/video';
import { ContentEditor } from './content_editor'; import { ContentEditor } from './content_editor';
import createMarkdownSerializer from './markdown_serializer'; import createMarkdownSerializer from './markdown_serializer';
import trackInputRulesAndShortcuts from './track_input_rules_and_shortcuts'; import trackInputRulesAndShortcuts from './track_input_rules_and_shortcuts';
...@@ -104,6 +105,7 @@ export const createContentEditor = ({ ...@@ -104,6 +105,7 @@ export const createContentEditor = ({
TaskItem, TaskItem,
TaskList, TaskList,
Text, Text,
Video,
]; ];
const allExtensions = [...builtInContentEditorExtensions, ...extensions]; const allExtensions = [...builtInContentEditorExtensions, ...extensions];
......
...@@ -35,6 +35,7 @@ import TableRow from '../extensions/table_row'; ...@@ -35,6 +35,7 @@ import TableRow from '../extensions/table_row';
import TaskItem from '../extensions/task_item'; import TaskItem from '../extensions/task_item';
import TaskList from '../extensions/task_list'; import TaskList from '../extensions/task_list';
import Text from '../extensions/text'; import Text from '../extensions/text';
import Video from '../extensions/video';
import { import {
isPlainURL, isPlainURL,
renderHardBreak, renderHardBreak,
...@@ -151,6 +152,7 @@ const defaultSerializerConfig = { ...@@ -151,6 +152,7 @@ const defaultSerializerConfig = {
else defaultMarkdownSerializer.nodes.bullet_list(state, node); else defaultMarkdownSerializer.nodes.bullet_list(state, node);
}, },
[Text.name]: defaultMarkdownSerializer.nodes.text, [Text.name]: defaultMarkdownSerializer.nodes.text,
[Video.name]: renderPlayable,
}, },
}; };
......
...@@ -173,13 +173,16 @@ ...@@ -173,13 +173,16 @@
Hi @gitlab - thank you for reporting this ~bug (#1) we hope to fix it in %1.1 as part of !1 Hi @gitlab - thank you for reporting this ~bug (#1) we hope to fix it in %1.1 as part of !1
- name: audio - name: audio
markdown: '![Sample Audio](https://gitlab.com/gitlab.mp3)' markdown: '![Sample Audio](https://gitlab.com/gitlab.mp3)'
- name: audio_in_lists - name: video
markdown: '![Sample Video](https://gitlab.com/gitlab.mp4)'
- name: audio_and_video_in_lists
markdown: |- markdown: |-
* ![Sample Audio](https://gitlab.com/1.mp3) * ![Sample Audio](https://gitlab.com/1.mp3)
* ![Sample Audio](https://gitlab.com/2.mp3) * ![Sample Video](https://gitlab.com/2.mp4)
1. ![Sample Audio](https://gitlab.com/1.mp3) 1. ![Sample Video](https://gitlab.com/1.mp4)
2. ![Sample Audio](https://gitlab.com/2.mp3) 2. ![Sample Audio](https://gitlab.com/2.mp3)
* [x] ![Sample Audio](https://gitlab.com/1.mp3) * [x] ![Sample Audio](https://gitlab.com/1.mp3)
* [x] ![Sample Audio](https://gitlab.com/2.mp3) * [x] ![Sample Audio](https://gitlab.com/2.mp3)
* [x] ![Sample Video](https://gitlab.com/3.mp4)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment