packages/netlify-cms-widget-markdown/src/serializers/slateRemark.js
function convertNode(node, children) {
  switch (node.type) {
    /**
     * General
     *
     * Convert simple cases that only require a type and children, with no
     * additional properties.
     */
    case 'root':
    case 'paragraph':
    case 'quote':
    case 'list-item':
    case 'table':
    case 'table-row':
    case 'table-cell': {
      return u(typeMap[node.type], children);
    }

    /**
     * Shortcodes
     *
     * Shortcode nodes only exist in Slate's Raw AST if they were inserted
     * via the plugin toolbar in memory, so they should always have
     * shortcode data attached. The "shortcode" data property contains the
     * name of the registered shortcode plugin, and the "shortcodeData" data
     * property contains the data received from the shortcode plugin's
     * `fromBlock` method when the shortcode node was created.
     *
     * Here we create a `shortcode` MDAST node that contains only the shortcode
     * data.
     */
    case 'shortcode': {
      const { data } = node;
      return u(typeMap[node.type], { data });
    }

    /**
     * Headings
     *
     * Slate schemas don't usually infer basic type info from data, so each
     * level of heading is a separately named type. The MDAST schema just
     * has a single "heading" type with the depth stored in a "depth"
     * property on the node. Here we derive the depth from the Slate node
     * type - e.g., for "heading-two", we need a depth value of "2".
     */
    case 'heading-one':
    case 'heading-two':
    case 'heading-three':
    case 'heading-four':
    case 'heading-five':
    case 'heading-six': {
      const depthMap = { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6 };
      const depthText = node.type.split('-')[1];
      const depth = depthMap[depthText];
      return u(typeMap[node.type], { depth }, children);
    }

    /**
     * Code Blocks
     *
     * Code block nodes have a single text child, and may have a code language
     * stored in the "lang" data property. Here we transfer both the node
     * value and the "lang" data property to the new MDAST node.
     */
    case 'code': {
      const value = flatMap(node.nodes, child => {
        return flatMap(child.leaves, 'text');
      }).join('');
      const { lang, ...data } = get(node, 'data', {});
      return u(typeMap[node.type], { lang, data }, value);
    }

    /**
     * Lists
     *
     * Our Slate schema has separate node types for ordered and unordered
     * lists, but the MDAST spec uses a single type with a boolean "ordered"
     * property to indicate whether the list is numbered. The MDAST spec also
     * allows for a "start" property to indicate the first number used for an
     * ordered list. Here we translate both values to our Slate schema.
     */
    case 'numbered-list':
    case 'bulleted-list': {
      const ordered = node.type === 'numbered-list';
      const props = { ordered, start: get(node.data, 'start') || 1 };
      return u(typeMap[node.type], props, children);
    }

    /**
     * Breaks
     *
     * Breaks don't have children. We parse them separately for clarity.
     */
    case 'break':
    case 'thematic-break': {
      return u(typeMap[node.type]);
    }

    /**
     * Links
     *
     * The url and title attributes of link nodes are stored in properties on
     * the node for both Slate and Remark schemas.
     */
    case 'link': {
      const { url, title, ...data } = get(node, 'data', {});
      return u(typeMap[node.type], { url, title, data }, children);
    }

    /**
     * Images
     *
     * This transformation is almost identical to that of links, except for the
     * lack of child nodes and addition of `alt` attribute data.
     */
    case 'image': {
      const { url, title, alt, ...data } = get(node, 'data', {});
      return u(typeMap[node.type], { url, title, alt, data });
    }

    /**
     * No default case is supplied because an unhandled case should never
     * occur. In the event that it does, let the error throw (for now).
     */
  }
}
function convertNode(node, children) {
  switch (node.type) {
    /**
     * General
     *
     * Convert simple cases that only require a type and children, with no
     * additional properties.
     */
    case 'root':
    case 'paragraph':
    case 'quote':
    case 'list-item':
    case 'table':
    case 'table-row':
    case 'table-cell': {
      return u(typeMap[node.type], children);
    }

    /**
     * Shortcodes
     *
     * Shortcode nodes only exist in Slate's Raw AST if they were inserted
     * via the plugin toolbar in memory, so they should always have
     * shortcode data attached. The "shortcode" data property contains the
     * name of the registered shortcode plugin, and the "shortcodeData" data
     * property contains the data received from the shortcode plugin's
     * `fromBlock` method when the shortcode node was created.
     *
     * Here we create a `shortcode` MDAST node that contains only the shortcode
     * data.
     */
    case 'shortcode': {
      const { data } = node;
      return u(typeMap[node.type], { data });
    }

    /**
     * Headings
     *
     * Slate schemas don't usually infer basic type info from data, so each
     * level of heading is a separately named type. The MDAST schema just
     * has a single "heading" type with the depth stored in a "depth"
     * property on the node. Here we derive the depth from the Slate node
     * type - e.g., for "heading-two", we need a depth value of "2".
     */
    case 'heading-one':
    case 'heading-two':
    case 'heading-three':
    case 'heading-four':
    case 'heading-five':
    case 'heading-six': {
      const depthMap = { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6 };
      const depthText = node.type.split('-')[1];
      const depth = depthMap[depthText];
      return u(typeMap[node.type], { depth }, children);
    }

    /**
     * Code Blocks
     *
     * Code block nodes have a single text child, and may have a code language
     * stored in the "lang" data property. Here we transfer both the node
     * value and the "lang" data property to the new MDAST node.
     */
    case 'code': {
      const value = flatMap(node.nodes, child => {
        return flatMap(child.leaves, 'text');
      }).join('');
      const { lang, ...data } = get(node, 'data', {});
      return u(typeMap[node.type], { lang, data }, value);
    }

    /**
     * Lists
     *
     * Our Slate schema has separate node types for ordered and unordered
     * lists, but the MDAST spec uses a single type with a boolean "ordered"
     * property to indicate whether the list is numbered. The MDAST spec also
     * allows for a "start" property to indicate the first number used for an
     * ordered list. Here we translate both values to our Slate schema.
     */
    case 'numbered-list':
    case 'bulleted-list': {
      const ordered = node.type === 'numbered-list';
      const props = { ordered, start: get(node.data, 'start') || 1 };
      return u(typeMap[node.type], props, children);
    }

    /**
     * Breaks
     *
     * Breaks don't have children. We parse them separately for clarity.
     */
    case 'break':
    case 'thematic-break': {
      return u(typeMap[node.type]);
    }

    /**
     * Links
     *
     * The url and title attributes of link nodes are stored in properties on
     * the node for both Slate and Remark schemas.
     */
    case 'link': {
      const { url, title, ...data } = get(node, 'data', {});
      return u(typeMap[node.type], { url, title, data }, children);
    }

    /**
     * Images
     *
     * This transformation is almost identical to that of links, except for the
     * lack of child nodes and addition of `alt` attribute data.
     */
    case 'image': {
      const { url, title, alt, ...data } = get(node, 'data', {});
      return u(typeMap[node.type], { url, title, alt, data });
    }

    /**
     * No default case is supplied because an unhandled case should never
     * occur. In the event that it does, let the error throw (for now).
     */
  }
}
function convertNode ( node , children ) { switch ( node . type ) { /**
     * General
     *
     * Convert simple cases that only require a type and children, with no
     * additional properties.
     */ case 'root' : case 'paragraph' : case 'quote' : case 'list-item' : case 'table' : case 'table-row' : case 'table-cell' : { return u ( typeMap [ node . type ] , children ) ; } /**
     * Shortcodes
     *
     * Shortcode nodes only exist in Slate's Raw AST if they were inserted
     * via the plugin toolbar in memory, so they should always have
     * shortcode data attached. The "shortcode" data property contains the
     * name of the registered shortcode plugin, and the "shortcodeData" data
     * property contains the data received from the shortcode plugin's
     * `fromBlock` method when the shortcode node was created.
     *
     * Here we create a `shortcode` MDAST node that contains only the shortcode
     * data.
     */ case 'shortcode' : { const { data } = node ; return u ( typeMap [ node . type ] , { data } ) ; } /**
     * Headings
     *
     * Slate schemas don't usually infer basic type info from data, so each
     * level of heading is a separately named type. The MDAST schema just
     * has a single "heading" type with the depth stored in a "depth"
     * property on the node. Here we derive the depth from the Slate node
     * type - e.g., for "heading-two", we need a depth value of "2".
     */ case 'heading-one' : case 'heading-two' : case 'heading-three' : case 'heading-four' : case 'heading-five' : case 'heading-six' : { const depthMap = { one : 1 , two : 2 , three : 3 , four : 4 , five : 5 , six : 6 } ; const depthText = node . type . split ( '-' ) [ 1 ] ; const depth = depthMap [ depthText ] ; return u ( typeMap [ node . type ] , { depth } , children ) ; } /**
     * Code Blocks
     *
     * Code block nodes have a single text child, and may have a code language
     * stored in the "lang" data property. Here we transfer both the node
     * value and the "lang" data property to the new MDAST node.
     */ case 'code' : { const value = flatMap ( node . nodes , child => { return flatMap ( child . leaves , 'text' ) ; } ) . join ( '' ) ; const { lang , ... data } = get ( node , 'data' , { } ) ; return u ( typeMap [ node . type ] , { lang , data } , value ) ; } /**
     * Lists
     *
     * Our Slate schema has separate node types for ordered and unordered
     * lists, but the MDAST spec uses a single type with a boolean "ordered"
     * property to indicate whether the list is numbered. The MDAST spec also
     * allows for a "start" property to indicate the first number used for an
     * ordered list. Here we translate both values to our Slate schema.
     */ case 'numbered-list' : case 'bulleted-list' : { const ordered = node . type === 'numbered-list' ; const props = { ordered , start : get ( node . data , 'start' ) || 1 } ; return u ( typeMap [ node . type ] , props , children ) ; } /**
     * Breaks
     *
     * Breaks don't have children. We parse them separately for clarity.
     */ case 'break' : case 'thematic-break' : { return u ( typeMap [ node . type ] ) ; } /**
     * Links
     *
     * The url and title attributes of link nodes are stored in properties on
     * the node for both Slate and Remark schemas.
     */ case 'link' : { const { url , title , ... data } = get ( node , 'data' , { } ) ; return u ( typeMap [ node . type ] , { url , title , data } , children ) ; } /**
     * Images
     *
     * This transformation is almost identical to that of links, except for the
     * lack of child nodes and addition of `alt` attribute data.
     */ case 'image' : { const { url , title , alt , ... data } = get ( node , 'data' , { } ) ; return u ( typeMap [ node . type ] , { url , title , alt , data } ) ; } /**
     * No default case is supplied because an unhandled case should never
     * occur. In the event that it does, let the error throw (for now).
     */ } }
Convert a single Slate Raw node to an MDAST node. Uses the unist-builder `u`
function to create MDAST nodes.
Convert a single Slate Raw node to an MDAST node . Uses the unist - builder u function to create MDAST nodes .