2025-08-10 15:21:49 +03:00
|
|
|
import type { CSSProperties } from "preact/compat";
|
2025-08-07 20:08:51 +03:00
|
|
|
|
|
|
|
|
type HTMLElementLike = string | HTMLElement | JQuery<HTMLElement>;
|
|
|
|
|
|
2025-08-05 20:35:53 +03:00
|
|
|
interface RawHtmlProps {
|
2025-08-06 18:38:52 +03:00
|
|
|
className?: string;
|
2025-08-07 20:08:51 +03:00
|
|
|
html: HTMLElementLike;
|
|
|
|
|
style?: CSSProperties;
|
2025-08-05 20:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-07 22:00:37 +03:00
|
|
|
export default function RawHtml(props: RawHtmlProps) {
|
|
|
|
|
return <span {...getProps(props)} />;
|
2025-08-06 18:38:52 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-07 22:00:37 +03:00
|
|
|
export function RawHtmlBlock(props: RawHtmlProps) {
|
|
|
|
|
return <div {...getProps(props)} />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getProps({ className, html, style }: RawHtmlProps) {
|
|
|
|
|
return {
|
|
|
|
|
className: className,
|
|
|
|
|
dangerouslySetInnerHTML: getHtml(html),
|
|
|
|
|
style
|
|
|
|
|
}
|
2025-08-06 18:38:52 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-18 11:21:09 +03:00
|
|
|
export function getHtml(html: string | HTMLElement | JQuery<HTMLElement>) {
|
2025-08-07 20:08:51 +03:00
|
|
|
if (typeof html === "object" && "length" in html) {
|
|
|
|
|
html = html[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof html === "object" && "outerHTML" in html) {
|
2025-08-06 18:38:52 +03:00
|
|
|
html = html.outerHTML;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
2025-08-07 20:08:51 +03:00
|
|
|
__html: html as string
|
2025-08-06 18:38:52 +03:00
|
|
|
};
|
2025-08-05 20:35:53 +03:00
|
|
|
}
|