1.0.5 • Published 1 year ago

@theneo/editor-parser v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

THENEO EDITOR PARSER for nodejs

This parser is written for converting markdown + html mix string to Platejs from udecode plate editor value or slate json and from json to renderable html for inject into dom using dangerouslySetInnerHTML

if you have enabled import in nodejs you can directly import like This

const editorParser = import('@theneo/editor-parser').default;

otherwise import like below in any async function

const editorParser = (await import('@theneo/editor-parser')).default;

example:

// section  = array of string
// update is async function

// editorParser = {
//      deserializeMd, -> method for converting markdown + html string to plate value or slate json
//      createPlateEditor, -> method for creating plate editor instance
//      serializeHtml, -> method for converting slate json or plate value to html
//      plugins, -> default set of customized plugins for editor instance
// }

const update = async () => {
  console.time("start");

  const editor = createPlateEditor({
    plugins,
  });

  const array = [];

  sections.forEach((item) => {
    const json = deserializeMd(editor, item);
    const html = serializeHtml(editor, { nodes: json });

    array.push({ html, json });

  });
  console.timeEnd("start");

  fs.writeFileSync(
    "./output.json",
    JSON.stringify(array, null, 2)
  );
};

update();