Skip to content

Commit

Permalink
Update Markdown.php
Browse files Browse the repository at this point in the history
  • Loading branch information
peterujah authored Nov 4, 2024
1 parent d08d3ff commit d9edae2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ class Markdown extends Parsedown
/**
* Media type.
*
* @var string $mediaType
* @var array<string,string> $mediaType
*/
protected string $mediaType = 'audio/ogg; codecs=opus';
protected array $mediaType = [
'audio' => 'audio/ogg; codecs=opus',
'video' => 'video/mp4'
];

/**
* Hostname link.
Expand Down Expand Up @@ -187,16 +190,17 @@ public function tableOfContents(bool $enable = true): self
/**
* Set media type
*
* @param string $type
* @param string $context The media context type (e.g, `audio`, `video`).
* @param string $type The attribute of media type (e.g, `audio/ogg; codecs=opus`).
*
* @return self
*/
public function setMediaType(string $type): self
public function setMediaType(string $context, string $type): self
{
$this->mediaType = $type;
$this->mediaType[$context] = $type;

return $this;
}
}

/**
* Get table of contents.
Expand Down Expand Up @@ -263,7 +267,7 @@ protected function blockMedia(array $Line, ?array $Block = null): array

$html = '<figure class="media-player">';
$html .= ($isVideo ? '<video controls id="'.$id.'">' : '<audio controls id="'.$id.'">');
$html .= '<source src="' . $sanitizeLink . '" type="' . $this->mediaType . '">';
$html .= '<source src="' . $sanitizeLink . '" type="' . $this->mediaType[$typeLower] . '">';
$html .= 'Your browser does not support the '.$typeLower.' element.';
$html .= ' <a href="' . $sanitizeLink . '">Download '.$typeLower.'</a>';
$html .= ($isVideo ? '</video>' : '</audio>');
Expand Down Expand Up @@ -400,5 +404,4 @@ public static function toKebabCase(string $string): string

return mb_strtolower($string);
}

}

0 comments on commit d9edae2

Please sign in to comment.