Skip to content

Restrict the creation of elements inside other elements (i.e. tables) #1005

Closed Answered by bensquire
bensquire asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone thats wondering:

To strip out unwanted elements from tables

// See: https://docs.slatejs.org/concepts/11-normalizing
export const withPreventTableChildren = (
	disallowedBlockTypes = [ELEMENT_CODE_BLOCK, ELEMENT_BLOCKQUOTE, ELEMENT_HR],
	disallowedInlineTypes = [ELEMENT_H1, ELEMENT_H2, ELEMENT_H3, ELEMENT_H4, ELEMENT_H5, ELEMENT_H6]
) => (editor) => {
	const { normalizeNode } = editor

	editor.normalizeNode = ([currentNode, currentPath]) => {
		if (!Element.isElement(currentNode) || (currentNode.type !== ELEMENT_TD && currentNode.type !== ELEMENT_TH)) {
			return normalizeNode([currentNode, currentPath])
		}

		for (const [childNode, childPath] of Node.children(editor, currentPath

Replies: 2 comments 4 replies

Comment options

bensquire
Sep 13, 2021
Collaborator Author

You must be logged in to vote
4 replies
@dylans
Comment options

@bensquire
Comment options

bensquire Sep 14, 2021
Collaborator Author

@karthikcodes6
Comment options

@bensquire
Comment options

bensquire Sep 14, 2021
Collaborator Author

Comment options

bensquire
Sep 14, 2021
Collaborator Author

You must be logged in to vote
0 replies
Answer selected by zbeyens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants