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 @gitlab/require-i18n-strings */
import { defaultMarkdownSerializer } from 'prosemirror-markdown';
import { Node } from 'tiptap';
......@@ -30,19 +31,19 @@ export default class Playable extends Node {
const parseDOM = [
{
tag: `.media-container`,
tag: `.${this.mediaType}-container`,
getAttrs: (el) => ({
src: el.querySelector('audio,video').src,
alt: el.querySelector('audio,video').dataset.title,
src: el.querySelector(this.mediaType).src,
alt: el.querySelector(this.mediaType).dataset.title,
}),
},
];
const toDOM = (node) => [
'span',
{ class: 'media-container' },
{ class: `media-container ${this.mediaType}-container` },
[
this.options.mediaType,
this.mediaType,
{
src: node.attrs.src,
controls: true,
......
import Playable from './playable';
export default Playable.extend({
name: 'audio',
defaultOptions: {
...Playable.options,
mediaType: 'audio',
......
/* eslint-disable @gitlab/require-i18n-strings */
import { Node } from '@tiptap/core';
const queryPlayableElement = (element, mediaType) => element.querySelector(mediaType);
export default Node.create({
name: 'playable',
group: 'inline',
inline: true,
draggable: true,
......@@ -46,7 +47,7 @@ export default Node.create({
parseHTML() {
return [
{
tag: '.media-container',
tag: `.${this.options.mediaType}-container`,
},
];
},
......@@ -54,7 +55,7 @@ export default Node.create({
renderHTML({ node }) {
return [
'span',
{ class: 'media-container' },
{ class: `media-container ${this.options.mediaType}-container` },
[
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';
import TaskItem from '../extensions/task_item';
import TaskList from '../extensions/task_list';
import Text from '../extensions/text';
import Video from '../extensions/video';
import { ContentEditor } from './content_editor';
import createMarkdownSerializer from './markdown_serializer';
import trackInputRulesAndShortcuts from './track_input_rules_and_shortcuts';
......@@ -104,6 +105,7 @@ export const createContentEditor = ({
TaskItem,
TaskList,
Text,
Video,
];
const allExtensions = [...builtInContentEditorExtensions, ...extensions];
......
......@@ -35,6 +35,7 @@ import TableRow from '../extensions/table_row';
import TaskItem from '../extensions/task_item';
import TaskList from '../extensions/task_list';
import Text from '../extensions/text';
import Video from '../extensions/video';
import {
isPlainURL,
renderHardBreak,
......@@ -151,6 +152,7 @@ const defaultSerializerConfig = {
else defaultMarkdownSerializer.nodes.bullet_list(state, node);
},
[Text.name]: defaultMarkdownSerializer.nodes.text,
[Video.name]: renderPlayable,
},
};
......
......@@ -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
- name: audio
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: |-
* ![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)
* [x] ![Sample Audio](https://gitlab.com/1.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