How to use @contentful/rich-text-types - 10 common examples

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 / index.ts View on Github external
function nodeToHtmlString(node: CommonNode, { renderNode, renderMark }: Options): string {
  if (helpers.isText(node)) {
    const nodeValue = escape(node.value);
    if (node.marks.length > 0) {
      return node.marks.reduce((value: string, mark: Mark) => {
        if (!renderMark[mark.type]) {
          return value;
        }
        return renderMark[mark.type](value);
      }, nodeValue);
    }

    return nodeValue;
  } else {
    const nextNode: Next = nodes => nodeListToHtmlString(nodes, { renderMark, renderNode });
    if (!node.nodeType || !renderNode[node.nodeType]) {
      // TODO: Figure what to return when passed an unrecognized node.
      return '';
github storybynumbers / rich-text-to-react / src / index.js View on Github external
const renderNode = (node, key, next) => {
  const nodeRenderer = next.node
  if (helpers.isText(node)) {
    // We're at final tip of node branch, can render text.
    const markerRender = next.mark
    return nodeRenderer.text(node, key, markerRender)
  } else {
    const nextNode = nodes => renderNodeList(nodes, key, next)
    if (!nodeRenderer) {
      return <div>{`${key} ;lost nodeRenderer`}</div>
    }
    if (!node.nodeType || !nodeRenderer[node.nodeType]) {
      // TODO: Figure what to return when passed an unrecognized node.
      return '(Unrecognized node type)'
    }
    return nodeRenderer[node.nodeType](node, key, nextNode)
  }
}
github contentful / rich-text / packages / rich-text-html-renderer / src / __test__ / documents / inline-entity.ts View on Github external
marks: [],
                value: '',
                nodeType: 'text',
                data: {},
              },
            ],
            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 / 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 / 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 connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.spec.js View on Github external
it('should return an HTML tag if no override matches', () => {
      const type = BLOCKS.PARAGRAPH;
      const overrides = { foo: { component: Override } };
      const actual = RichTextService.getElement(type, overrides);
      expect(actual).toBe('p');
    });
github connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.spec.js View on Github external
it('should return an override by the node type', () => {
      const type = BLOCKS.PARAGRAPH;
      const overrides = { [BLOCKS.PARAGRAPH]: 'foo' };
      const actual = RichTextService.getOverride(type, overrides);
      expect(actual).toBe('foo');
    });
  });