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

Video Support #849

Open
pixlmint opened this issue Mar 20, 2023 · 1 comment
Open

Video Support #849

pixlmint opened this issue Mar 20, 2023 · 1 comment

Comments

@pixlmint
Copy link

The goal is to allow videos to be embedded just like images

In GitHub Markdown that works by having the link to a video surrounded by 2 empty lines. According to some blogs, in regular Markdown that's supposed to work exactly like with images, so like ![video title](video link). Now, perhaps Parsedown already has this, but if so then it doesn't work with .webm video files.

And just to clarify, when I talk about embedding I don't mean from sites like YouTube, but actual Video files

@peterujah
Copy link

To do this you can extend the class and create a blockMedia like below.

<?php 
class Markdown extends \Parsedown{
  public function __construct(){
    $this->BlockTypes["{"] = array('Media');
    $this->InlineTypes["{"] = array('Media');
  }

    protected function blockMedia($Line, $Block = null) {
        if (preg_match('/^(\s*)\{(.+?)\}\((.+?)\)\((\S+?)\)$/', $Line['body'], $matches)){
            
            $description = $matches[2];
            $type = $matches[3];
            $link = $matches[4];
    
            $html = '';
            if (strtolower($type) === 'video') {
                $html .= '<video controls>';
            } else {
                $html .= '<audio controls>';
            }
            $html .= '<source src="' . htmlspecialchars($link) . '">';
            if (strtolower($type) === 'video') {
                $html .= '</video>';
            } else {
                $html .= '</audio>';
            }
            $html .= '<p>' . htmlspecialchars($description) . ' (' . htmlspecialchars($type) . ')</p>';

            $Block = array(
                'markup' => $html,
            );

            return $Block;
        }
    }

}

Now to format video use this
{Video Description}(video)(https://example.com/video.mp4)
{Audio Description}(audio)(https://example.com/audio.mp3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants