Added a way to add html to content
This commit is contained in:
@@ -7,17 +7,30 @@ import { PageBlocksContent } from "../../tina/__generated__/types";
|
||||
import { tinaField } from "tinacms/dist/react";
|
||||
import { PageBlockFunction } from "../blocks-renderer";
|
||||
import inlineComponents, { richTextTemplates } from "../inline/inline-definitions";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
|
||||
const HTMLInline = (props: { value: string }) => {
|
||||
const createSanitizedMarkup = (text: string) => {
|
||||
return { __html: sanitizeHtml(text, {
|
||||
allowedAttributes: {
|
||||
div: [ "class" ]
|
||||
}
|
||||
}) };
|
||||
};
|
||||
|
||||
return <span dangerouslySetInnerHTML={ createSanitizedMarkup(props.value) } />;
|
||||
};
|
||||
|
||||
export const Content: PageBlockFunction<PageBlocksContent> = ({ data }) => {
|
||||
return (
|
||||
<Section>
|
||||
<Container
|
||||
className={ "prose prose-lg" }
|
||||
className={ "" }
|
||||
data-tina-field={ tinaField(data, "body") }
|
||||
size="large"
|
||||
width="medium"
|
||||
>
|
||||
<TinaMarkdown components={ inlineComponents } content={ data.body } />
|
||||
<TinaMarkdown components={ { ...inlineComponents, html: props => <HTMLInline { ...props } /> } } content={ data.body } />
|
||||
</Container>
|
||||
</Section>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user