Skip to content

Commit

Permalink
Allow ha-hls-player in markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
davet2001 committed Jul 1, 2024
1 parent d01377d commit e6bd503
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/components/ha-hls-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 8 additions & 4 deletions src/components/ha-markdown-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/resources/markdown-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e6bd503

Please sign in to comment.