Skip to content

Instantly share code, notes, and snippets.

@vnugent
Created November 15, 2021 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vnugent/d8df85ec4e22ca9c6f78dc5fb2658c1b to your computer and use it in GitHub Desktop.
Save vnugent/d8df85ec4e22ca9c6f78dc5fb2658c1b to your computer and use it in GitHub Desktop.
Create your own Platejs plugin
// 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