mirror of
https://github.com/Redocly/redoc.git
synced 2025-11-10 20:57:33 +03:00
* chore(deps): bump dompurify from 3.1.3 to 3.2.4 Bumps [dompurify](https://github.com/cure53/DOMPurify) from 3.1.3 to 3.2.4. - [Release notes](https://github.com/cure53/DOMPurify/releases) - [Commits](https://github.com/cure53/DOMPurify/compare/3.1.3...3.2.4) --- updated-dependencies: - dependency-name: dompurify dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): update dompurify --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: kanoru <kanoru3101@gmail.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import * as DOMPurify from 'dompurify';
|
|
import * as React from 'react';
|
|
|
|
import { OptionsConsumer } from '../OptionsProvider';
|
|
import { StylingMarkdownProps } from './Markdown';
|
|
import { StyledMarkdownBlock } from './styled.elements';
|
|
import styled from 'styled-components';
|
|
|
|
// Workaround for DOMPurify type issues (https://github.com/cure53/DOMPurify/issues/1034)
|
|
const dompurify = DOMPurify['default'] as DOMPurify.DOMPurify;
|
|
|
|
const StyledMarkdownSpan = styled(StyledMarkdownBlock)`
|
|
display: inline;
|
|
`;
|
|
|
|
const sanitize = (sanitize, html) => (sanitize ? dompurify.sanitize(html) : html);
|
|
|
|
export function SanitizedMarkdownHTML({
|
|
inline,
|
|
compact,
|
|
...rest
|
|
}: StylingMarkdownProps & { html: string; className?: string; 'data-role'?: string }) {
|
|
const Wrap = inline ? StyledMarkdownSpan : StyledMarkdownBlock;
|
|
|
|
return (
|
|
<OptionsConsumer>
|
|
{options => (
|
|
<Wrap
|
|
className={'redoc-markdown ' + (rest.className || '')}
|
|
dangerouslySetInnerHTML={{
|
|
__html: sanitize(options.sanitize, rest.html),
|
|
}}
|
|
data-role={rest['data-role']}
|
|
{...rest}
|
|
$inline={inline}
|
|
$compact={compact}
|
|
/>
|
|
)}
|
|
</OptionsConsumer>
|
|
);
|
|
}
|