Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deserializer/parser issue #35

Open
bhirt opened this issue Apr 27, 2019 · 3 comments
Open

deserializer/parser issue #35

bhirt opened this issue Apr 27, 2019 · 3 comments

Comments

@bhirt
Copy link

bhirt commented Apr 27, 2019

It looks like support in deserializer seems to have a problem with markdown that should generate a leaf with multiple marks. This simple code demonstrates the issue.

import MarkdownSerializer from 'slate-md-serializer'

const Serializer = new MarkdownSerializer()
const test1 = "This is **_bold and italic_**."
const d1 = Serializer.deserialize(test1)
console.log(JSON.stringify(d1,null,2))

outputs

{
  "object": "value",
  "document": {
    "object": "document",
    "data": {},
    "nodes": [
      {
        "object": "block",
        "type": "paragraph",
        "data": {},
        "nodes": [
          {
            "object": "text",
            "leaves": [
              {
                "object": "leaf",
                "text": "This is ",
                "marks": []
              }
            ]
          },
          {
            "object": "text",
            "leaves": [
              {
                "object": "leaf",
                "text": "bold and italic",
                "marks": [
                  {
                    "object": "mark",
                    "type": "italic",
                    "data": {}
                  }
                ]
              },
              {
                "object": "leaf",
                "text": ".",
                "marks": []
              }
            ]
          }
        ]
      }
    ]
  }
}
@tommoor
Copy link
Owner

tommoor commented Apr 27, 2019

Some clues as to what caused this in the conversation here,
outline/outline#443

@bhirt
Copy link
Author

bhirt commented Apr 27, 2019

I noticed that https://github.com/markedjs/marked handles my input correctly. It also seem to have more exhaustive rules than slate-md-serializer (but underscore is a new slate-md-serializer rule that cause problems). I am looking into this further. I did try updated the regex rules and captures to what marked is using, butit fails.

A quick debugging sessions shows that Renderer.prototype.strong and Renderer.prototype.em are both being called on my test input, but each time they create a new array of marks. My expected behavior would be the first call to create a marks array and the second call appends a mark to the existing one.

Is this something that would be committed if a sutable fix was found?

@tommoor
Copy link
Owner

tommoor commented Apr 27, 2019

Is this something that would be committed if a sutable fix was found?

Absolutely, that would be great. The library also has extensive regression tests, I'd recommend a TDD approach to working with the lib – writing the failing test first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants