Files
Trilium/apps/client/src/widgets/react/RawHtml.tsx

39 lines
910 B
TypeScript
Raw Normal View History

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
}
export default function RawHtml(props: RawHtmlProps) {
return <span {...getProps(props)} />;
2025-08-06 18:38:52 +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
}
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
}