From f1c24665cee9c213b586c239aae0814c900fe763 Mon Sep 17 00:00:00 2001 From: Corey Ward Date: Fri, 26 Feb 2021 11:05:59 -0600 Subject: [PATCH] Fix: pass object-type mark props through to serializer --- src/index.jsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/index.jsx b/src/index.jsx index 1691086..0ce8674 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -154,8 +154,22 @@ const buildSerializer = (serializers) => { const scrubMarkProps = (serializers) => Object.entries(serializers).reduce((output, [name, serializer]) => { if (serializer) { - const wrapper = ({ _type, _key, mark, markKey, children, ...props }) => - React.createElement(serializer, props, children) + const wrapper = ({ _type, _key, mark, markKey, children, ...props }) => { + // Sometimes the `mark` prop is a string that we want to ignore, + // but other times it is an object with _key, _type, and other + // props that we want to pass through. In that case, we iterate + // through the `mark` object properties and add them to the + // `props` that we pass to the serializer. + if (typeof mark === "object") { + const { _type, _key, ...markProps } = mark + Object.entries(markProps).forEach(([name, value]) => { + props[name] = value + }) + } + + return React.createElement(serializer, props, children) + } + wrapper.displayName = `${upperFirst(name)}Wrapper` output[name] = wrapper }