How to use the @contentful/rich-text-types.BLOCKS.EMBEDDED_ENTRY 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 / 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 connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.spec.js View on Github external
it('should render an embedded entry block override', () => {
      const overrides = {
        [BLOCKS.EMBEDDED_ENTRY]: { page: Override }
      };
      const actual = RichTextService.entryNodeToJsx(embeddedEntryBlock, {
        ...options,
        overrides
      });
      expect(actual).toMatchSnapshot();
    });
github contentful / rich-text / packages / rich-text-links / bin / benchmark / get-rich-text-entity-links.ts View on Github external
],
    },
    {
      nodeType: BLOCKS.PARAGRAPH,
      data: {},
      content: [
        {
          nodeType: 'text',
          data: {},
          marks: [],
          value: 'The first chapter is free to read: ',
        },
      ],
    },
    {
      nodeType: BLOCKS.EMBEDDED_ENTRY,
      data: {
        target: {
          sys: {
            id: 'chapter-1',
            type: 'Link',
            linkType: 'Entry',
          },
        },
      },
      content: [
        {
          nodeType: 'text',
          data: {},
          marks: [],
          value: '',
        },
github keenethics / keenethics / pages / post.js View on Github external
[BLOCKS.PARAGRAPH]: (node, children) => {
      const filteredChildren = children.filter((item) => !!item);

      if (filteredChildren.length === 1 && typeof filteredChildren[0] === 'object') {
        return filteredChildren[0];
      }

      return <p>{children.filter((item) =&gt; !!item)}</p>;
    },
    [BLOCKS.EMBEDDED_ASSET]: (node) =&gt; {
      const { url } = node.data.target.fields.file;
      const { description, title } = node.data.target.fields;

      return imageComponent({ src: url, description, title });
    },
    [BLOCKS.EMBEDDED_ENTRY]: (node) =&gt; {
      if (_.get(node, 'data.target.sys.contentType.sys.id') === 'usefulReadings') {
        const { bookList, list } = _.get(node, 'data.target.fields', null);

        return (
          <div>
            <div>
              <img src="/static/images/book_icon.png" alt="Book icon">
            </div>
            <div>
              <h4>useful readings:</h4>
              {(bookList || list) &amp;&amp; documentToReactComponents(bookList || list)}
            </div>
          </div>
        );
      }
      if (_.get(node, 'data.target.sys.contentType.sys.id') === 'mostSuitableFor') {
github connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.js View on Github external
[BLOCKS.HEADING_6]: 'h6',
  [BLOCKS.PARAGRAPH]: 'p',
  [BLOCKS.UL_LIST]: 'ul',
  [BLOCKS.OL_LIST]: 'ol',
  [BLOCKS.LIST_ITEM]: 'li',
  [BLOCKS.QUOTE]: 'blockquote',
  [BLOCKS.HR]: 'hr',
  [INLINES.HYPERLINK]: 'a',
  [MARKS.BOLD]: 'strong',
  [MARKS.ITALIC]: 'em',
  [MARKS.UNDERLINE]: 'u',
  [MARKS.CODE]: 'code'
};

const entryMap = {
  [BLOCKS.EMBEDDED_ENTRY]: true,
  [INLINES.ENTRY_HYPERLINK]: true,
  [INLINES.EMBEDDED_ENTRY]: true
};

const assetMap = {
  [BLOCKS.EMBEDDED_ASSET]: true,
  [INLINES.ASSET_HYPERLINK]: true
};

function isEntryNode(node) {
  return entryMap[node.nodeType];
}

function isAssetNode(node) {
  return assetMap[node.nodeType];
}
github connor-baer / rich-text-to-jsx / src / __fixtures__ / index.js View on Github external
};

export const embeddedEntryInline = {
  data: {
    target: entry
  },
  content: [],
  nodeType: INLINES.EMBEDDED_ENTRY
};

export const embeddedEntryBlock = {
  data: {
    target: entry
  },
  content: [],
  nodeType: BLOCKS.EMBEDDED_ENTRY
};
github storybynumbers / rich-text-to-react / src / index.js View on Github external
const defaultMarkRenderers = {
  [MARKS.BOLD]: (text, key) =&gt; <strong>{text}</strong>,
  [MARKS.ITALIC]: (text, key) =&gt; <em>{text}</em>,
  [MARKS.UNDERLINE]: (text, key) =&gt; <u>{text}</u>,
  [MARKS.CODE]: (text, key) =&gt; <code>{text}</code>
}

const defaultNodeRenderers = {
  [BLOCKS.PARAGRAPH]: (node, key, next) =&gt; <p>{next(node.content, key, next)}</p>,
  [BLOCKS.HEADING_1]: (node, key, next) =&gt; <h1>{next(node.content, key, next)}</h1>,
  [BLOCKS.HEADING_2]: (node, key, next) =&gt; <h2>{next(node.content, key, next)}</h2>,
  [BLOCKS.HEADING_3]: (node, key, next) =&gt; <h3>{next(node.content, key, next)}</h3>,
  [BLOCKS.HEADING_4]: (node, key, next) =&gt; <h4>{next(node.content, key, next)}</h4>,
  [BLOCKS.HEADING_5]: (node, key, next) =&gt; <h5>{next(node.content, key, next)}</h5>,
  [BLOCKS.HEADING_6]: (node, key, next) =&gt; <h6>{next(node.content, key, next)}</h6>,
  [BLOCKS.EMBEDDED_ENTRY]: (node, key, next) =&gt; <div>{next(node.content, key, next)}</div>,
  [BLOCKS.UL_LIST]: (node, key, next) =&gt; <ul>{next(node.content, key, next)}</ul>,
  [BLOCKS.OL_LIST]: (node, key, next) =&gt; <ol>{next(node.content, key, next)}</ol>,
  [BLOCKS.LIST_ITEM]: (node, key, next) =&gt; <li>{next(node.content, key, next)}</li>,
  [BLOCKS.QUOTE]: (node, key, next) =&gt; <blockquote>{next(node.content, key, next)}</blockquote>,
  [BLOCKS.HR]: (node, key) =&gt; <hr>,
  [INLINES.ASSET_HYPERLINK]: (node, key) =&gt; defaultInline(INLINES.ASSET_HYPERLINK, node, key),
  [INLINES.ENTRY_HYPERLINK]: (node, key) =&gt; defaultInline(INLINES.ENTRY_HYPERLINK, node, key),
  [INLINES.EMBEDDED_ENTRY]: (node, key) =&gt; defaultInline(INLINES.EMBEDDED_ENTRY, node, key),
  [INLINES.HYPERLINK]: (node, key, next) =&gt; {
    return (<a href="{node.data.uri}">{next(node.content, key, next)}</a>)
  },
  text: ({ marks, value }, key, markRenderer) =&gt; {
    return marks.length ? (
      marks.reduce((aggregate, mark, i) =&gt; markRenderer[mark.type](aggregate, `${key}-${i}`), value)
    ) : value
  }
github contentful / rich-text / packages / rich-text-links / bin / benchmark / get-rich-text-entity-links.ts View on Github external
data: {},
          marks: [],
          value: '',
        },
      ],
    },
    {
      nodeType: BLOCKS.UL_LIST,
      data: {},
      content: [
        {
          nodeType: BLOCKS.LIST_ITEM,
          data: {},
          content: [
            {
              nodeType: BLOCKS.EMBEDDED_ENTRY,
              data: {
                target: {
                  sys: {
                    id: 'chapter-2',
                    type: 'Link',
                    linkType: 'Entry',
                  },
                },
              },
              content: [
                {
                  nodeType: 'text',
                  data: {},
                  marks: [],
                  value: '',
                },
github contentful / rich-text / packages / rich-text-html-renderer / src / index.ts View on Github external
MARKS,
  INLINES,
  Block,
  Inline,
  helpers,
} from '@contentful/rich-text-types';

const defaultNodeRenderers: RenderNode = {
  [BLOCKS.PARAGRAPH]: (node, next) =&gt; `<p>${next(node.content)}</p>`,
  [BLOCKS.HEADING_1]: (node, next) =&gt; `<h1>${next(node.content)}</h1>`,
  [BLOCKS.HEADING_2]: (node, next) =&gt; `<h2>${next(node.content)}</h2>`,
  [BLOCKS.HEADING_3]: (node, next) =&gt; `<h3>${next(node.content)}</h3>`,
  [BLOCKS.HEADING_4]: (node, next) =&gt; `<h4>${next(node.content)}</h4>`,
  [BLOCKS.HEADING_5]: (node, next) =&gt; `<h5>${next(node.content)}</h5>`,
  [BLOCKS.HEADING_6]: (node, next) =&gt; `<h6>${next(node.content)}</h6>`,
  [BLOCKS.EMBEDDED_ENTRY]: (node, next) =&gt; `<div>${next(node.content)}</div>`,
  [BLOCKS.UL_LIST]: (node, next) =&gt; `<ul>${next(node.content)}</ul>`,
  [BLOCKS.OL_LIST]: (node, next) =&gt; `<ol>${next(node.content)}</ol>`,
  [BLOCKS.LIST_ITEM]: (node, next) =&gt; `<li>${next(node.content)}</li>`,
  [BLOCKS.QUOTE]: (node, next) =&gt; `<blockquote>${next(node.content)}</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),
  [INLINES.HYPERLINK]: (node, next) =&gt; `<a href="${node.data.uri}">${next(node.content)}</a>`,
};

const defaultMarkRenderers: RenderMark = {
  [MARKS.BOLD]: text =&gt; `<b>${text}</b>`,
  [MARKS.ITALIC]: text =&gt; `<i>${text}</i>`,
  [MARKS.UNDERLINE]: text =&gt; `<u>${text}</u>`,
  [MARKS.CODE]: text =&gt; `<code>${text}</code>`,