From e6bd503384bc2f47473bfb111a9da9db904ab31a Mon Sep 17 00:00:00 2001 From: Dave T <17680170+davet2001@users.noreply.github.com> Date: Mon, 1 Jul 2024 22:47:17 +0000 Subject: [PATCH] Allow ha-hls-player in markdown --- src/components/ha-hls-player.ts | 10 +++++++++- src/components/ha-markdown-element.ts | 12 ++++++++---- src/resources/markdown-worker.ts | 7 +++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/components/ha-hls-player.ts b/src/components/ha-hls-player.ts index cf3ed5a526a1..0baa72b39339 100644 --- a/src/components/ha-hls-player.ts +++ b/src/components/ha-hls-player.ts @@ -150,7 +150,15 @@ class HaHLSPlayer extends LitElement { let playlist_url: string; if (match !== null && matchTwice === null) { // Only send the regular playlist url if we match exactly once - playlist_url = new URL(match[2], this.url).href; + // In case we arrive here with a relative URL, we need to provide a valid + // base/absolute URL to avoid the URL() constructor throwing an error. + let base_url: string; + try { + base_url = new URL(this.url).href; + } catch (TypeError) { + base_url = new URL(this.url, window.location.href).href; + } + playlist_url = new URL(match[2], base_url).href; } else { playlist_url = this.url; } diff --git a/src/components/ha-markdown-element.ts b/src/components/ha-markdown-element.ts index 5ca7fa66b262..e799a1346f70 100644 --- a/src/components/ha-markdown-element.ts +++ b/src/components/ha-markdown-element.ts @@ -108,12 +108,16 @@ class HaMarkdownElement extends ReactiveElement { } } else if ( node instanceof HTMLElement && - ["ha-alert", "ha-qr-code", "ha-icon", "ha-svg-icon"].includes( - node.localName - ) + [ + "ha-alert", + "ha-qr-code", + "ha-icon", + "ha-svg-icon", + "ha-hls-player", + ].includes(node.localName) ) { import( - /* webpackInclude: /(ha-alert)|(ha-qr-code)|(ha-icon)|(ha-svg-icon)/ */ `./${node.localName}` + /* webpackInclude: /(ha-alert)|(ha-qr-code)|(ha-icon)|(ha-svg-icon)|(ha-hls-player)/ */ `./${node.localName}` ); } } diff --git a/src/resources/markdown-worker.ts b/src/resources/markdown-worker.ts index 85949e3f2307..9acea4177106 100644 --- a/src/resources/markdown-worker.ts +++ b/src/resources/markdown-worker.ts @@ -42,6 +42,13 @@ const renderMarkdown = async ( "ha-icon": ["icon"], "ha-svg-icon": ["path"], "ha-alert": ["alert-type", "title"], + "ha-hls-player": [ + "controls", + "url", + "autoplay", + "playsinline", + "posterUrl", + ], "ha-qr-code": [ "data", "scale",