mirror of
https://github.com/Redocly/redoc.git
synced 2025-12-05 08:53:52 +03:00
31 lines
906 B
TypeScript
31 lines
906 B
TypeScript
import * as DOMPurify from 'dompurify';
|
|
import * as React from 'react';
|
|
|
|
import { OptionsConsumer } from '../OptionsProvider';
|
|
import { StylingMarkdownProps } from './Markdown';
|
|
import { StyledMarkdownBlock } from './styled.elements';
|
|
|
|
const StyledMarkdownSpan = StyledMarkdownBlock.withComponent('span');
|
|
|
|
const sanitize = (untrustedSpec, html) => (untrustedSpec ? DOMPurify.sanitize(html) : html);
|
|
|
|
export function SanitizedMarkdownHTML(
|
|
props: StylingMarkdownProps & { html: string; className?: string },
|
|
) {
|
|
const Wrap = props.inline ? StyledMarkdownSpan : StyledMarkdownBlock;
|
|
|
|
return (
|
|
<OptionsConsumer>
|
|
{options => (
|
|
<Wrap
|
|
className={'redoc-markdown ' + (props.className || '')}
|
|
dangerouslySetInnerHTML={{
|
|
__html: sanitize(options.untrustedSpec, props.html),
|
|
}}
|
|
{...props}
|
|
/>
|
|
)}
|
|
</OptionsConsumer>
|
|
);
|
|
}
|