From 571eca5bc42c39293c4ca858b709272b3aa56f6d Mon Sep 17 00:00:00 2001 From: Roman <64708726+madromas@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:48:43 -0400 Subject: [PATCH 1/5] Added mp4 video support --- src/Parser.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Parser.php b/src/Parser.php index bfc60a8..16571a6 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -238,6 +238,29 @@ private function createIframe(array $attrs) return $iframe; } + private function parseVideo($block) + { + $class = $this->addClass($block->type); + + $div = $this->dom->createElement('div'); + + $div->setAttribute('class', $class); + + $video = $this->dom->createElement('video'); + + $video->setAttribute('src', $block->data->url); + $video->setAttribute('controls', $block->data->controls); + $video->setAttribute('autoplay', $block->data->autoplay); + $video->setAttribute('muted', $block->data->muted); + $video->setAttribute('stretched', $block->data->stretched); + + $video->appendChild($div); + + $video->appendChild($this->html5->loadHTMLFragment($block->data->url)); + + $this->dom->appendChild($video); + } + private function parseRaw($block) { $class = $this->addClass($block->type); From 1f87d80cad4af47a39493e85c07aadbe66f48e6f Mon Sep 17 00:00:00 2001 From: Roman <64708726+madromas@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:50:01 -0400 Subject: [PATCH 2/5] Added video parser --- src/HtmlParser.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/HtmlParser.php b/src/HtmlParser.php index 3916934..02e41c4 100644 --- a/src/HtmlParser.php +++ b/src/HtmlParser.php @@ -471,6 +471,21 @@ private function parseQuote($node, $styles) { return $block; } + /** + * Video Parser + * + * @param object $node + * @param array $styles + * @return array + */ + private function parseVideo($node, $styles) { + + $block['type'] = 'video'; + $block['data']['url'] = $this->setInnerHtml($node); + + return $block; + } + /** * Embed Parser * From ec71dac3a5f6c100e1c23f2f9428d20f2e14a265 Mon Sep 17 00:00:00 2001 From: Roman <64708726+madromas@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:57:44 -0400 Subject: [PATCH 3/5] added video --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 92efe30..04a0b4f 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Package | Key | Main CSS Class
(with default prefix) | Additional / modificat `@editorjs/simple-image` | `simpleImage` | `.prs-image` | additional:
`.prs_withborder`
`.prs_withbackground`
`.prs_stretched` `@editorjs/embed` | `embed` | `.prs-embed` | additional:
`.prs_youtube`
`.prs_codepen`
`.prs_vimeo` `@editorjs/link` | `linkTool` | `.prs-linktool` | additional:
`.prs_title`
`.prs_description`
`.prs_sitename` +`@editorjs/simple-video-editorjs` | `SimpleVideo` | `.prs-video` | additional:
`stretched`
`autoplay`
`muted`
`controls` `@editorjs/delimiter` | `delimiter` | `.prs-delimiter` | `editorjs-alert` | `alert` | `.prs-alert` | alignment:
`.prs_left`
`.prs_right`
`.prs_center`
additional:
`.prs_primary`
`.prs_secondary`
`.prs_info`
`.prs_success`
`.prs_warning`
`.prs_danger`
`.prs_light`
`.prs_dark` `@editorjs/warning` | `warning` | `.prs-warning` | @@ -141,6 +142,14 @@ Return Editor.js content blocks ``` +##### Video + +```html +
+ +
+``` + ##### Code ```html From c42d7e0027bcf0fd447b3a43fc94ee76bfaa2a47 Mon Sep 17 00:00:00 2001 From: Roman <64708726+madromas@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:22:47 -0400 Subject: [PATCH 4/5] Update Parser.php --- src/Parser.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 16571a6..60e2ae0 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -240,11 +240,22 @@ private function createIframe(array $attrs) private function parseVideo($block) { - $class = $this->addClass($block->type); - $div = $this->dom->createElement('div'); + $figure = $this->dom->createElement('div'); + + $attrs = []; + + $caption = (!empty($block->data->caption)) ? $block->data->caption : ''; + + if ($block->data->withBorder) $attrs[] = "withborder"; + if ($block->data->withBackground) $attrs[] = "withbackground"; + if ($block->data->stretched) $attrs[] = "stretched"; + + $style = (count($attrs) > 0) ? implode(' ', $attrs) : false; + + $class = $this->addClass($block->type, false, $style); - $div->setAttribute('class', $class); + $figure->setAttribute('class', $class); $video = $this->dom->createElement('video'); @@ -253,13 +264,20 @@ private function parseVideo($block) $video->setAttribute('autoplay', $block->data->autoplay); $video->setAttribute('muted', $block->data->muted); $video->setAttribute('stretched', $block->data->stretched); - - $video->appendChild($div); - - $video->appendChild($this->html5->loadHTMLFragment($block->data->url)); - $this->dom->appendChild($video); + $figure->appendChild($video); + + $video->appendChild($this->html5->parseFragment($block->data->url)); + + if (!empty($caption)) { + $figCaption = $this->dom->createElement('figcaption'); + $figCaption->appendChild($this->html5->loadHTMLFragment($caption)); + $figure->appendChild($figCaption); + } + + $this->dom->appendChild($figure); } + private function parseRaw($block) { From bd4949ea0a4033f9c2a130b6d1a341cc131850b3 Mon Sep 17 00:00:00 2001 From: Roman <64708726+madromas@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:24:27 -0400 Subject: [PATCH 5/5] Update HtmlParser.php --- src/HtmlParser.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/HtmlParser.php b/src/HtmlParser.php index 02e41c4..d2a5dd4 100644 --- a/src/HtmlParser.php +++ b/src/HtmlParser.php @@ -480,10 +480,19 @@ private function parseQuote($node, $styles) { */ private function parseVideo($node, $styles) { +$withBorder = in_array('withborder', $styles) ? true : false; + $withBackground = in_array('withbackground', $styles) ? true : false; + $stretched = in_array('stretched', $styles) ? true : false; + $block['type'] = 'video'; - $block['data']['url'] = $this->setInnerHtml($node); - + $block['data']['url'] = $node->getElementsByTagName('video')->item(0)->getAttribute('src'); + $block['data']['caption'] = $this->setInnerHtml($node->getElementsByTagName('figcaption')->item(0)); + $block['data']['withBorder'] = $withBorder; + $block['data']['withBackground'] = $withBackground; + $block['data']['stretched'] = $stretched; + return $block; + } /**