summaryrefslogtreecommitdiff
path: root/examples/snowpack/src/components/ContentfulRichText.jsx
blob: 1f4528f6bd2c15053955a16cc37bb84276d4eb75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { BLOCKS, MARKS } from '@contentful/rich-text-types';
import { documentToHtmlString } from '@contentful/rich-text-html-renderer';

const options = {
  renderMark: {
    [MARKS.BOLD]: (text) => `<custom-bold>${text}<custom-bold>`,
  },
  renderNode: {
    [BLOCKS.PARAGRAPH]: (node, next) =>
      `<custom-paragraph>${next(node.content)}</custom-paragraph>`,
  },
};

export function RichTextDocument({ document }) {
  return (
    <div
      dangerouslySetInnerHTML={{
        html: documentToHtmlString(document, options),
      }}
    />
  );
}