How to use the @contentful/rich-text-types.BLOCKS.DOCUMENT function in @contentful/rich-text-types

To help you get started, we’ve selected a few @contentful/rich-text-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github contentful / rich-text / packages / rich-text-html-renderer / src / __test__ / documents / invalid-type.ts View on Github external
import { Document, BLOCKS } from '@contentful/rich-text-types';

export default {
  nodeType: BLOCKS.DOCUMENT,
  data: {},
  content: [
    {
      nodeType: 'UNRECOGNIZED_TYPE' as BLOCKS,
      data: {},
      content: [
        {
          nodeType: 'text',
          value: 'Hello world!',
          marks: [],
          data: {},
        },
      ],
    },
  ],
} as Document;
github contentful / rich-text / packages / rich-text-html-renderer / src / __test__ / documents / embedded-entry.ts View on Github external
export default function(entry: Object) {
  return {
    nodeType: BLOCKS.DOCUMENT,
    data: {},
    content: [
      {
        nodeType: BLOCKS.EMBEDDED_ENTRY,
        content: [],
        data: {
          target: entry,
        },
      },
    ],
  } as Document;
}
github contentful / rich-text / packages / rich-text-html-renderer / src / __test__ / documents / inline-entity.ts View on Github external
},
            ],
            nodeType: inlineType,
          },
          {
            marks: [],
            value: '',
            nodeType: 'text',
            data: {},
          },
        ],
        nodeType: BLOCKS.PARAGRAPH,
      },
    ],
    data: {},
    nodeType: BLOCKS.DOCUMENT,
  } as Document;
}
github contentful / rich-text / packages / rich-text-html-renderer / src / __test__ / documents / heading.ts View on Github external
export default function(heading: string) {
  return {
    nodeType: BLOCKS.DOCUMENT,
    data: {},
    content: [
      {
        nodeType: heading,
        data: {},
        content: [
          {
            nodeType: 'text',
            value: 'hello world',
            marks: [],
            data: {},
          },
        ],
      },
    ],
  } as Document;
github contentful / rich-text / packages / rich-text-plain-text-renderer / bin / benchmark / get-rich-text-entity-links.ts View on Github external
import { BLOCKS, Document, UnorderedList, ListItem, Text, Node } from '@contentful/rich-text-types';
import { documentToPlainTextString as docToString } from '../../src/index';

/**
 * Implements just a subset of _.times since all we're really doing here is
 * cleanly filling the field with a bunch of junk data.
 */
function times(n: number, node: N): N[] {
  return new Array(n).fill(node);
}

const richTextField: Document = {
  nodeType: BLOCKS.DOCUMENT,
  data: {},
  content: [
    {
      nodeType: BLOCKS.PARAGRAPH,
      data: {},
      content: times(8000, {
        nodeType: BLOCKS.UL_LIST,
        data: {},
        content: times(5, {
          nodeType: BLOCKS.LIST_ITEM,
          data: {},
          content: [
            {
              nodeType: BLOCKS.PARAGRAPH,
              data: {},
              content: times(5, {
github contentful / rich-text / packages / rich-text-links / bin / benchmark / get-rich-text-entity-links.ts View on Github external
import { Document, BLOCKS, INLINES } from '@contentful/rich-text-types';
import richTextLinks from '../../src/index';

const richTextField: Document = {
  nodeType: BLOCKS.DOCUMENT,
  data: {},
  content: [
    {
      nodeType: BLOCKS.PARAGRAPH,
      data: {},
      content: [
        {
          nodeType: 'text',
          data: {},
          marks: [],
          value: '',
        },
        {
          nodeType: INLINES.ASSET_HYPERLINK,
          data: {
            target: {
github contentful / rich-text / packages / rich-text-from-markdown / src / index.ts View on Github external
const astToRichTextDocument = async (
  tree: MarkdownTree,
  fallback: FallbackResolver,
): Promise => {
  const content = await mdToRichTextNodes(tree.children, fallback);
  return {
    nodeType: BLOCKS.DOCUMENT,
    data: {},
    content: content as TopLevelBlock[],
  };
};
github contentful / rich-text / packages / rich-text-react-renderer / src / index.tsx View on Github external
import React, { ReactNode } from 'react';
import { Block, BLOCKS, Document, Inline, INLINES, MARKS, Text } from '@contentful/rich-text-types';
import { nodeToReactComponent } from './util/nodeListToReactComponents';

const defaultNodeRenderers: RenderNode = {
  [BLOCKS.DOCUMENT]: (node, children) => children,
  [BLOCKS.PARAGRAPH]: (node, children) =&gt; <p>{children}</p>,
  [BLOCKS.HEADING_1]: (node, children) =&gt; <h1>{children}</h1>,
  [BLOCKS.HEADING_2]: (node, children) =&gt; <h2>{children}</h2>,
  [BLOCKS.HEADING_3]: (node, children) =&gt; <h3>{children}</h3>,
  [BLOCKS.HEADING_4]: (node, children) =&gt; <h4>{children}</h4>,
  [BLOCKS.HEADING_5]: (node, children) =&gt; <h5>{children}</h5>,
  [BLOCKS.HEADING_6]: (node, children) =&gt; <h6>{children}</h6>,
  [BLOCKS.EMBEDDED_ENTRY]: (node, children) =&gt; <div>{children}</div>,
  [BLOCKS.UL_LIST]: (node, children) =&gt; <ul>{children}</ul>,
  [BLOCKS.OL_LIST]: (node, children) =&gt; <ol>{children}</ol>,
  [BLOCKS.LIST_ITEM]: (node, children) =&gt; <li>{children}</li>,
  [BLOCKS.QUOTE]: (node, children) =&gt; <blockquote>{children}</blockquote>,
  [BLOCKS.HR]: () =&gt; <hr>,
  [INLINES.ASSET_HYPERLINK]: node =&gt; defaultInline(INLINES.ASSET_HYPERLINK, node as Inline),
  [INLINES.ENTRY_HYPERLINK]: node =&gt; defaultInline(INLINES.ENTRY_HYPERLINK, node as Inline),
  [INLINES.EMBEDDED_ENTRY]: node =&gt; defaultInline(INLINES.EMBEDDED_ENTRY, node as Inline),