mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 11:01:45 +00:00
feat: migrate from raw HTML to JSX (TSX / SolidJS) (#3583)
Co-authored-by: Su-Yong <simssy2205@gmail.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { defaultTrustedTypePolicy } from '@/utils/trusted-types';
|
||||
const domParser = new DOMParser();
|
||||
|
||||
/**
|
||||
* Creates a DOM element from an HTML string
|
||||
@ -6,13 +6,8 @@ import { defaultTrustedTypePolicy } from '@/utils/trusted-types';
|
||||
* @returns The DOM element
|
||||
*/
|
||||
export const ElementFromHtml = (html: string): HTMLElement => {
|
||||
const template = document.createElement('template');
|
||||
html = html.trim(); // Never return a text node of whitespace as the result
|
||||
(template.innerHTML as string | TrustedHTML) = defaultTrustedTypePolicy
|
||||
? defaultTrustedTypePolicy.createHTML(html)
|
||||
: html;
|
||||
|
||||
return template.content.firstElementChild as HTMLElement;
|
||||
return (domParser.parseFromString(html, 'text/html') as HTMLDocument).body
|
||||
.firstElementChild as HTMLElement;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user