tommoor / slate-md-serializer

A Markdown serializer for the Slate editor framework
MIT License
64 stars 36 forks source link

Deserializing empty string is incorrect #18

Closed Lukavyi closed 6 years ago

Lukavyi commented 6 years ago
import MarkDownSerializer from "slate-md-serializer";
const markdown = new MarkDownSerializer();

markdown.deserialize('');
// produces
const md = {
  object: "value",
  document: {
    object: "document",
    data: {},
    nodes: []
  }
};

produces different result than

import Plain from "slate-plain-serializer";

Plain.deserialize('');
// produces
const plain = {
  object: "value",
  document: {
    object: "document",
    data: {},
    nodes: [
      {
        object: "block",
        type: "line",
        isVoid: false,
        data: {},
        nodes: [
          {
            object: "text",
            leaves: [
              {
                object: "leaf",
                text: "",
                marks: []
              }
            ]
          }
        ]
      }
    ]
  }
};

This leads to errors in console while trying to type something in slate editor instance with that Value object

tommoor commented 6 years ago

Happy to see this fixed up, however I'd recommend using a schema in your Slate editor to ensure that there is always at least a single paragraph block. This is what we do in https://github.com/outline/rich-markdown-editor and https://github.com/outline/outline which seems to have avoided this issue

Lukavyi commented 6 years ago

Thanks for the tip, I'll try adding schema.