Created
November 15, 2021 13:12
-
-
Save vnugent/d8df85ec4e22ca9c6f78dc5fb2658c1b to your computer and use it in GitHub Desktop.
Create your own Platejs plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// createCustomNormalizingPlugin.js | |
import { getChildren } from "@udecode/plate-common"; | |
import { getPlatePluginWithOverrides, isElement } from "@udecode/plate-core"; | |
const withCustomNormalizing = (options) => (editor) => { | |
const { normalizeNode } = editor; | |
editor.normalizeNode = ([node, path]) => { | |
//console.log("#foos ", node); | |
if (node.type === "p") { | |
for (const child of node.children) { | |
console.log("# node", child); | |
//return; | |
} | |
} | |
// if ( ) { | |
// // do some transformations | |
// return // if transformed | |
// } | |
normalizeNode([node, path]); // continue the normalization chain if not transformed | |
}; | |
return editor; | |
}; | |
export const createCustomNormalizingPlugin = getPlatePluginWithOverrides( | |
withCustomNormalizing | |
); | |
// PlateEditor.js | |
import { createCustomNormalizingPlugin } from "./createCustomNormalizingPlugin"; | |
const plugins = [ | |
// ... other plugins | |
createCustomNormalizingPlugin(), | |
]; | |
return <Plate plugins={plugins} | |
// other props | |
/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment