How to use the @contentful/rich-text-types.helpers.isText 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 / 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-react-renderer / src / util / nodeListToReactComponents.tsx View on Github external
export function nodeToReactComponent(node: CommonNode, options: Options): ReactNode {
  const { renderNode, renderMark, renderText } = options;
  if (helpers.isText(node)) {
    return node.marks.reduce((value: ReactNode, mark: Mark): ReactNode =&gt; {
      if (!renderMark[mark.type]) {
        return value;
      }
      return renderMark[mark.type](value);
    }, renderText ? renderText(node.value) : node.value);
  } else {
    const children: ReactNode = nodeListToReactComponents(node.content, options);
    if (!node.nodeType || !renderNode[node.nodeType]) {
      return &lt;&gt;{children};
    }
    return renderNode[node.nodeType](node, children);
  }
}
github connor-baer / rich-text-to-jsx / src / rich-text-to-jsx.js View on Github external
export function nodeToJsx(node = {}, options = {}, key) {
  const { nodeType } = node;

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

  if (helpers.isText(node)) {
    return textNodeToJsx(node, options, key);
  }

  if (isEntryNode(node)) {
    return entryNodeToJsx(node, options, key);
  }

  if (isAssetNode(node)) {
    return assetNodeToJsx(node, options, key);
  }

  return parentNodeToJsx(node, options, key);
}
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;
  }, '');
}