diff --git a/src/app/Markdown/MediaUrlResolver.php b/src/app/Markdown/MediaUrlResolver.php
index 89f5ff6..a4dfe5d 100644
--- a/src/app/Markdown/MediaUrlResolver.php
+++ b/src/app/Markdown/MediaUrlResolver.php
@@ -6,12 +6,15 @@ class MediaUrlResolver
{
private const VIDEO_EXT = ['mp4', 'webm', 'ogv', 'mov', 'm4v'];
+ private const AUDIO_EXT = ['mp3', 'wav', 'ogg', 'm4a'];
+
public function resolve(string $url): ?string
{
if ($url === '') {
return null;
}
- return $this->detectVideo($url);
+ return $this->detectVideo($url)
+ ?? $this->detectAudio($url);
}
private function detectVideo(string $url): ?string
@@ -23,6 +26,15 @@ private function detectVideo(string $url): ?string
return "";
}
+ private function detectAudio(string $url): ?string
+ {
+ if (!in_array($this->getPathExtension($url), self::AUDIO_EXT, true)) {
+ return null;
+ }
+ $safe = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
+ return "";
+ }
+
private function getPathExtension(string $url): string
{
$path = parse_url($url, PHP_URL_PATH);
diff --git a/src/tests/Unit/Markdown/MediaUrlResolverTest.php b/src/tests/Unit/Markdown/MediaUrlResolverTest.php
index c24411a..2a64cad 100644
--- a/src/tests/Unit/Markdown/MediaUrlResolverTest.php
+++ b/src/tests/Unit/Markdown/MediaUrlResolverTest.php
@@ -67,4 +67,24 @@ public function test_video_url_is_html_escaped(): void
$this->assertStringNotContainsString('"quote.mp4"', $html);
$this->assertStringContainsString('"', $html);
}
+
+ #[DataProvider('audioUrls')]
+ public function test_audio_urls_produce_audio_tag(string $url): void
+ {
+ $html = $this->resolver->resolve($url);
+ $this->assertNotNull($html);
+ $this->assertStringStartsWith('