Skip to content
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

added mp4 video link parser #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Package | Key | Main CSS Class<br>(with default prefix) | Additional / modificat
`@editorjs/simple-image` | `simpleImage` | `.prs-image` | additional:<br>`.prs_withborder`<br>`.prs_withbackground`<br>`.prs_stretched`
`@editorjs/embed` | `embed` | `.prs-embed` | additional:<br>`.prs_youtube`<br>`.prs_codepen`<br>`.prs_vimeo`
`@editorjs/link` | `linkTool` | `.prs-linktool` | additional:<br>`.prs_title`<br>`.prs_description`<br>`.prs_sitename`
`@editorjs/simple-video-editorjs` | `SimpleVideo` | `.prs-video` | additional:<br>`stretched`<br>`autoplay`<br>`muted`<br>`controls`
`@editorjs/delimiter` | `delimiter` | `.prs-delimiter` |
`editorjs-alert` | `alert` | `.prs-alert` | alignment:<br>`.prs_left`<br>`.prs_right`<br>`.prs_center`<br>additional:<br>`.prs_primary`<br>`.prs_secondary`<br>`.prs_info`<br>`.prs_success`<br>`.prs_warning`<br>`.prs_danger`<br>`.prs_light`<br>`.prs_dark`
`@editorjs/warning` | `warning` | `.prs-warning` |
Expand Down Expand Up @@ -141,6 +142,14 @@ Return Editor.js content blocks
</table>
```

##### Video

```html
<div class="prs-video">
<video src="" controls muted autoplay stretched></video>
</div>
```

##### Code

```html
Expand Down
24 changes: 24 additions & 0 deletions src/HtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,30 @@ private function parseQuote($node, $styles) {
return $block;
}

/**
* Video Parser
*
* @param object $node
* @param array $styles
* @return array
*/
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'] = $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;

}

/**
* Embed Parser
*
Expand Down
41 changes: 41 additions & 0 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,47 @@ private function createIframe(array $attrs)
return $iframe;
}

private function parseVideo($block)
{

$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);

$figure->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);

$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)
{
$class = $this->addClass($block->type);
Expand Down