add embeded audio

This commit is contained in:
Dennis Eichhorn 2023-11-10 04:22:55 +00:00
parent 171413c108
commit fa3d48bc24

View File

@ -513,7 +513,7 @@ class Markdown
} }
// Embedding // Embedding
$state = $this->options['embedding'] ?? false; $state = $this->options['embeding'] ?? false;
if ($state !== false) { if ($state !== false) {
$this->inlineTypes['['][] = 'Embeding'; $this->inlineTypes['['][] = 'Embeding';
$this->inlineMarkerList .= '['; $this->inlineMarkerList .= '[';
@ -1251,13 +1251,18 @@ class Markdown
*/ */
protected function inlineEmbeding(array $excerpt) : ?array protected function inlineEmbeding(array $excerpt) : ?array
{ {
if (!($this->options['embedding'] ?? false) if (!($this->options['embeding'] ?? false)
|| \preg_match('/\[video.*src="([^"]*)".*\]/', $excerpt['text'], $matches) !== 1 || (($video = (\preg_match('/\[video.*src="([^"]*)".*\]/', $excerpt['text'], $matches) !== 1))
&& ($audio = (\preg_match('/\[audio.*src="([^"]*)".*\]/', $excerpt['text'], $matches) !== 1)))
) { ) {
return null; return null;
} }
$video = !$video;
$audio = !$audio;
$url = $matches[1]; $url = $matches[1];
if ($video) {
$type = ''; $type = '';
$needles = ['youtube', 'vimeo', 'dailymotion']; $needles = ['youtube', 'vimeo', 'dailymotion'];
@ -1300,16 +1305,35 @@ class Markdown
break; break;
default: default:
$element = 'video'; $element = 'video';
$attributes = [
'src' => UriFactory::build($url),
'controls' => ''
];
} }
return [ return [
'extent' => strlen($matches[0]), 'extent' => \strlen($matches[0]),
'element' => [ 'element' => [
'name' => $element, 'name' => $element,
'text' => $matches[1], 'text' => $matches[1],
'attributes' => $attributes 'attributes' => $attributes
], ],
]; ];
} elseif ($audio) {
return [
'extent' => \strlen($matches[0]),
'element' => [
'name' => 'audio',
'text' => $matches[1],
'attributes' => [
'src' => UriFactory::build($url),
'controls' => ''
]
],
];
}
return null;
} }
/** /**