packages/netlify-cms-widget-markdown/src/serializers/slateRemark.js
function combineTextAndInline(nodes) {
  return nodes.reduce((acc, node) => {
    const prevNode = last(acc);
    const prevNodeLeaves = get(prevNode, 'leaves');
    const data = node.data || {};

    /**
     * If the previous node has leaves and the current node has marks in data
     * (only happens when we place them on inline nodes here in the parser), or
     * the current node also has leaves (because the previous node was
     * originally an inline node that we've already squashed into a leaf)
     * combine the current node into the previous.
     */
    if (!isEmpty(prevNodeLeaves) && !isEmpty(data.marks)) {
      prevNodeLeaves.push({ node, marks: data.marks });
      return acc;
    }

    if (!isEmpty(prevNodeLeaves) && !isEmpty(node.leaves)) {
      prevNode.leaves = prevNodeLeaves.concat(node.leaves);
      return acc;
    }

    /**
     * Break nodes contain a single child text node with a newline character
     * for visual purposes in the editor, but Remark break nodes have no
     * children, so we remove the child node here.
     */
    if (node.type === 'break') {
      acc.push({ object: 'inline', type: 'break' });
      return acc;
    }

    /**
     * Convert remaining inline nodes to standalone text nodes with leaves.
     */
    if (node.object === 'inline') {
      acc.push({ object: 'text', leaves: [{ node, marks: data.marks }] });
      return acc;
    }

    /**
     * Only remaining case is an actual text node, can be pushed as is.
     */
    acc.push(node);
    return acc;
  }, []);
}
function combineTextAndInline(nodes) {
  return nodes.reduce((acc, node) => {
    const prevNode = last(acc);
    const prevNodeLeaves = get(prevNode, 'leaves');
    const data = node.data || {};

    /**
     * If the previous node has leaves and the current node has marks in data
     * (only happens when we place them on inline nodes here in the parser), or
     * the current node also has leaves (because the previous node was
     * originally an inline node that we've already squashed into a leaf)
     * combine the current node into the previous.
     */
    if (!isEmpty(prevNodeLeaves) && !isEmpty(data.marks)) {
      prevNodeLeaves.push({ node, marks: data.marks });
      return acc;
    }

    if (!isEmpty(prevNodeLeaves) && !isEmpty(node.leaves)) {
      prevNode.leaves = prevNodeLeaves.concat(node.leaves);
      return acc;
    }

    /**
     * Break nodes contain a single child text node with a newline character
     * for visual purposes in the editor, but Remark break nodes have no
     * children, so we remove the child node here.
     */
    if (node.type === 'break') {
      acc.push({ object: 'inline', type: 'break' });
      return acc;
    }

    /**
     * Convert remaining inline nodes to standalone text nodes with leaves.
     */
    if (node.object === 'inline') {
      acc.push({ object: 'text', leaves: [{ node, marks: data.marks }] });
      return acc;
    }

    /**
     * Only remaining case is an actual text node, can be pushed as is.
     */
    acc.push(node);
    return acc;
  }, []);
}
function combineTextAndInline ( nodes ) { return nodes . reduce ( ( acc , node ) => { const prevNode = last ( acc ) ; const prevNodeLeaves = get ( prevNode , 'leaves' ) ; const data = node . data || { } ; /**
     * If the previous node has leaves and the current node has marks in data
     * (only happens when we place them on inline nodes here in the parser), or
     * the current node also has leaves (because the previous node was
     * originally an inline node that we've already squashed into a leaf)
     * combine the current node into the previous.
     */ if ( ! isEmpty ( prevNodeLeaves ) && ! isEmpty ( data . marks ) ) { prevNodeLeaves . push ( { node , marks : data . marks } ) ; return acc ; } if ( ! isEmpty ( prevNodeLeaves ) && ! isEmpty ( node . leaves ) ) { prevNode . leaves = prevNodeLeaves . concat ( node . leaves ) ; return acc ; } /**
     * Break nodes contain a single child text node with a newline character
     * for visual purposes in the editor, but Remark break nodes have no
     * children, so we remove the child node here.
     */ if ( node . type === 'break' ) { acc . push ( { object : 'inline' , type : 'break' } ) ; return acc ; } /**
     * Convert remaining inline nodes to standalone text nodes with leaves.
     */ if ( node . object === 'inline' ) { acc . push ( { object : 'text' , leaves : [ { node , marks : data . marks } ] } ) ; return acc ; } /**
     * Only remaining case is an actual text node, can be pushed as is.
     */ acc . push ( node ) ; return acc ; } , [ ] ) ; }
Includes inline nodes as leaves in adjacent text nodes where appropriate, so
that mark node combining logic can apply to both text and inline nodes. This
is necessary because Slate doesn't allow inline nodes to have marks while
inline nodes in MDAST may be nested within mark nodes. Treating them as if
they were text is a bit of a necessary hack.
Includes inline nodes as leaves in adjacent text nodes where appropriate so that mark node combining logic can apply to both text and inline nodes . This is necessary because Slate doesn t allow inline nodes to have marks while inline nodes in MDAST may be nested within mark nodes . Treating them as if they were text is a bit of a necessary hack .