tommoor / slate-md-serializer

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

Over escaping characters #14

Open golmansax opened 6 years ago

golmansax commented 6 years ago

Hi, this issue is probably related to https://github.com/tommoor/slate-md-serializer/issues/9. I'm seeing extraneous backslashes on punctuation marks in text.

For example, I added this test:

test("Does not add extraneous backslashes", () => {
  expect(Markdown.serialize(Markdown.deserialize("(Hello!) Yay."))).toEqual("(Hello!) Yay.");
});

Which resulted in:

    expect(received).toEqual(expected)

    Expected value to equal:
      "(Hello!) Yay."
    Received:
      "\\(Hello\\!\\) Yay\\."

If you agree with the test I wrote, I'm happy to take a stab at this with a pull request. Let me know.

tommoor commented 6 years ago

Yea, the serializer is definitely over-safe when it comes to escaping right now. As the output is still valid Markdown and i've treated it as more important that the representation in Slate does not ever change between save and reload.

If you're able to make that test pass without failing the existing escaping tests then I'm very open to a PR. I do think the regex would have to get significantly more complex though?

golmansax commented 6 years ago

@tommoor I took a look at the source code and I understand what you mean. Some ideas of how to address this:

I'm also going to pass on it for now and re-visit if it becomes a more pressing issue.

tommoor commented 6 years ago

Add conditionals per punctuation mark (e.g. only escape # if at beginning of line).

If anyone wants to take on this improvement this seems like the way to go. The escaping will probably need splitting into multiple regex, one for each special character with it's own conditions.

golmansax commented 6 years ago

@tommoor A possible bug with over-escaping is that some markdown parsers automatically transform link text into link tags. So on my project, https://google.com (when written as text) is turning into https://google\.com.

I'll try to solve this at some point but wanted to let you know first.