Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
export default function(entry: Object) {
return {
nodeType: BLOCKS.DOCUMENT,
data: {},
content: [
{
nodeType: BLOCKS.EMBEDDED_ENTRY,
content: [],
data: {
target: entry,
},
},
],
} as Document;
}
},
],
nodeType: inlineType,
},
{
marks: [],
value: '',
nodeType: 'text',
data: {},
},
],
nodeType: BLOCKS.PARAGRAPH,
},
],
data: {},
nodeType: BLOCKS.DOCUMENT,
} as Document;
}
export default function(heading: string) {
return {
nodeType: BLOCKS.DOCUMENT,
data: {},
content: [
{
nodeType: heading,
data: {},
content: [
{
nodeType: 'text',
value: 'hello world',
marks: [],
data: {},
},
],
},
],
} as Document;
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, {
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: {
const astToRichTextDocument = async (
tree: MarkdownTree,
fallback: FallbackResolver,
): Promise => {
const content = await mdToRichTextNodes(tree.children, fallback);
return {
nodeType: BLOCKS.DOCUMENT,
data: {},
content: content as TopLevelBlock[],
};
};
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) => <p>{children}</p>,
[BLOCKS.HEADING_1]: (node, children) => <h1>{children}</h1>,
[BLOCKS.HEADING_2]: (node, children) => <h2>{children}</h2>,
[BLOCKS.HEADING_3]: (node, children) => <h3>{children}</h3>,
[BLOCKS.HEADING_4]: (node, children) => <h4>{children}</h4>,
[BLOCKS.HEADING_5]: (node, children) => <h5>{children}</h5>,
[BLOCKS.HEADING_6]: (node, children) => <h6>{children}</h6>,
[BLOCKS.EMBEDDED_ENTRY]: (node, children) => <div>{children}</div>,
[BLOCKS.UL_LIST]: (node, children) => <ul>{children}</ul>,
[BLOCKS.OL_LIST]: (node, children) => <ol>{children}</ol>,
[BLOCKS.LIST_ITEM]: (node, children) => <li>{children}</li>,
[BLOCKS.QUOTE]: (node, children) => <blockquote>{children}</blockquote>,
[BLOCKS.HR]: () => <hr>,
[INLINES.ASSET_HYPERLINK]: node => defaultInline(INLINES.ASSET_HYPERLINK, node as Inline),
[INLINES.ENTRY_HYPERLINK]: node => defaultInline(INLINES.ENTRY_HYPERLINK, node as Inline),
[INLINES.EMBEDDED_ENTRY]: node => defaultInline(INLINES.EMBEDDED_ENTRY, node as Inline),