How to use the @contentful/rich-text-types.helpers.isBlock 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 connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.js View on Github external
export function assetNodeToJsx(node, options, key) {
  const { data, content, nodeType } = node;
  const { overrides, createElement } = options;

  const mimeType = get(data, 'target.fields.file.contentType', '');
  const mimeTypeGroup = mimeType.split('/')[0];

  if (!mimeTypeGroup) {
    return unknownNodeToJsx(node, options, key);
  }

  const elementOverrides = overrides[nodeType];

  const BlockAsset = assetElementMap[mimeTypeGroup];
  const DefaultAsset = helpers.isBlock(node) ? BlockAsset : AssetLink;

  const element = getElement(mimeTypeGroup, elementOverrides) || DefaultAsset;

  if (!element) {
    return unknownNodeToJsx(node, options, key);
  }

  const props = getProps(nodeType, elementOverrides, {
    ...data.target,
    key
  });

  const children = isEmpty(content)
    ? undefined
    : nodeListToJsx(content, options);
github contentful / rich-text / packages / rich-text-plain-text-renderer / src / index.ts View on Github external
return (rootNode as Block).content.reduce((acc: string, node: Node, i: number): string => {
    let nodeTextValue: string;

    if (helpers.isText(node)) {
      nodeTextValue = node.value;
    } else if (helpers.isBlock(node) || helpers.isInline(node)) {
      nodeTextValue = documentToPlainTextString(node, blockDivisor);
      if (!nodeTextValue.length) {
        return acc;
      }
    }

    const nextNode = rootNode.content[i + 1];
    const isNextNodeBlock = nextNode && helpers.isBlock(nextNode);
    const divisor = isNextNodeBlock ? blockDivisor : '';
    return acc + nodeTextValue + divisor;
  }, '');
}
github contentful / rich-text / packages / rich-text-plain-text-renderer / src / index.ts View on Github external
return (rootNode as Block).content.reduce((acc: string, node: Node, i: number): string => {
    let nodeTextValue: string;

    if (helpers.isText(node)) {
      nodeTextValue = node.value;
    } else if (helpers.isBlock(node) || helpers.isInline(node)) {
      nodeTextValue = documentToPlainTextString(node, blockDivisor);
      if (!nodeTextValue.length) {
        return acc;
      }
    }

    const nextNode = rootNode.content[i + 1];
    const isNextNodeBlock = nextNode && helpers.isBlock(nextNode);
    const divisor = isNextNodeBlock ? blockDivisor : '';
    return acc + nodeTextValue + divisor;
  }, '');
}
github connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.js View on Github external
export function entryNodeToJsx(node, options, key) {
  const { data, content, nodeType } = node;
  const { overrides, createElement } = options;

  const contentType = get(data, 'target.sys.contentType.sys.id');

  if (!contentType) {
    return unknownNodeToJsx(node, options, key);
  }

  const elementOverrides = overrides[nodeType];

  const DefaultElement = helpers.isBlock(node) ? BlockElement : InlineElement;
  const element = getElement(contentType, elementOverrides) || DefaultElement;

  const props = getProps(nodeType, elementOverrides, {
    ...data.target,
    key
  });

  const children = isEmpty(content)
    ? undefined
    : nodeListToJsx(content, options);

  return createElement(element, props, children);
}