Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't config this thing #175

Open
ciokan opened this issue Oct 30, 2024 · 1 comment
Open

Can't config this thing #175

ciokan opened this issue Oct 30, 2024 · 1 comment

Comments

@ciokan
Copy link

ciokan commented Oct 30, 2024

I tried putting those settings (markMap or even alwaysEncodeBreakingEntities) everywhere with no effect:

export const Serialize = ({content, config = {}}: { content: any, config?: SlateToReactConfig }) => {
	return (
		<SlateToReact
			node={content}
			config={{
				...payloadSlateToReactConfig,
				markMap: {
					strikethrough: ['s'],
					bold         : ['strong'],
					underline    : ['u'],
					italic       : ['i'],
					code         : ['code'],
				},
				react  : {
					...payloadSlateToReactConfig.react,
					markMap          : {
						strikethrough: ['s'],
						bold         : ['strong'],
						underline    : ['u'],
						italic       : ['i'],
						code         : ['code'],
					},
					elementTransforms: {
						...payloadSlateToReactConfig.elementTransforms,
						upload: ({node, attribs, children}) => {
							if (node.value?.mimeType && node.value?.url) {
								if (node.value?.mimeType.match(/^image/)) {
									return (
										<img
											src={node.value.url}
											alt={node.value.alt || node.value.filename}
											className={"w-full border-2"}
										/>
									);
								}
							}
							return;
						}
					},
				},
				...config,
				alwaysEncodeBreakingEntities: false,
				html                        : {
					...payloadSlateToReactConfig.html,
					markMap                     : {
						strikethrough: ['s'],
						bold         : ['strong'],
						underline    : ['u'],
						italic       : ['i'],
						code         : ['code'],
					},
					alwaysEncodeBreakingEntities: false,
				}
			}}
		/>
	);
};

What is the correct way?

@thompsonsj
Copy link
Owner

thompsonsj commented Nov 4, 2024

Hey! Sorry, yes - it's not documented properly. I'll address that.

The config for SlateToReact is a bit strange- it is a kind of 'hybrid' config where the slateToDom config goes under a dom key and the React specific config (transform functions) go under a react key.

An example to illustrate #176.

I'll follow up with docs for this component. Might also review how the config is structured, make it as simple as possible.

thompsonsj added a commit that referenced this issue Nov 19, 2024
* test(react): add test to demonstrate #175

* style(__tests__): more descriptive test labels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants