mirror of
https://github.com/sern-handler/website
synced 2026-06-27 18:22:22 +00:00
42 lines
1.2 KiB
Plaintext
42 lines
1.2 KiB
Plaintext
---
|
|
import type { SanitizeOptions } from 'ultrahtml/transformers/sanitize'
|
|
import { createComponentProxy, html } from './utils';
|
|
|
|
export interface Props {
|
|
/** The HTML content to be rendered. If not provided, the content will be taken from the default slot.
|
|
* @example
|
|
*
|
|
<Markup
|
|
content={HTMLContent}
|
|
/>
|
|
*/
|
|
content?: string;
|
|
/** Allows the user to define custom SanitizeOptions to be used when rendering the HTML.
|
|
* @example
|
|
*
|
|
<Markup
|
|
sanitize={{ allowComponents: true }}
|
|
/>
|
|
*/
|
|
sanitize?: SanitizeOptions;
|
|
/** Allows the user to pass in custom components to be used when rendering the HTML.
|
|
* @example
|
|
*
|
|
<Markup
|
|
components={{ Heading, CodeBlock, CodeSpan, Note }}
|
|
/>
|
|
*/
|
|
components?: Record<string, any>;
|
|
}
|
|
|
|
const input = Astro.props.content ?? await Astro.slots.render('default');
|
|
if (!input) {
|
|
throw new Error('Unable to render <Markup> without a content prop or children')
|
|
}
|
|
// @ts-ignore
|
|
const components = createComponentProxy($$result, Astro.props.components);
|
|
const content = await html(input, { sanitize: Astro.props.sanitize, components });
|
|
---
|
|
|
|
<Fragment set:html={content} />
|