Skip to content

Instantly share code, notes, and snippets.

@vnugent
Created November 15, 2021 13:12
Show Gist options
  • Save vnugent/d8df85ec4e22ca9c6f78dc5fb2658c1b to your computer and use it in GitHub Desktop.
Save vnugent/d8df85ec4e22ca9c6f78dc5fb2658c1b to your computer and use it in GitHub Desktop.

Revisions

  1. vnugent created this gist Nov 15, 2021.
    44 changes: 44 additions & 0 deletions plate-custom-normalizer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    // 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
    />