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

Bug when translating link entities #122

Closed
Leonarto opened this issue May 21, 2020 · 8 comments
Closed

Bug when translating link entities #122

Leonarto opened this issue May 21, 2020 · 8 comments

Comments

@Leonarto
Copy link

Leonarto commented May 21, 2020

Hi!, your library is awesome!.

I've been encountering a cornercase bug. Whenever I set up a link entity on the end of the whole draft object, it breaks and translates to the following [LINK instead of [LINK]
(www.my_link.com)
. Any link entity ranged in between all blocks and chars work perfectly.

Example:

hello click here LINK_1
and here LINK_2

in that example LINK_1 translates to markdown but LINK_2 translates to [LINK_2

Thank you in advance!
Leo

@Rosey
Copy link
Owner

Rosey commented May 21, 2020

Thanks for the report! Sounds like it's worth digging into. As you may have read in the README I am crazy swamped with IRL demands right now so I may not get to this quickly but perhaps someone else will. Or if not, rest assured that I have seen your issue and will look into it whenever I do have time again.

@Rosey
Copy link
Owner

Rosey commented May 25, 2020

@Leonarto Not sure if you have the time, but if you do it would be helpful to have the raw draftjs object you're trying to convert to markdown, as well as any additional options you may be passing in (preserve newlines?). I've been trying to re-create your error but everything seems to be working ok for me.

Here's an example of a raw draftjs object that worked as expected -

{
   "entityMap":{
      "6":{
         "type":"LINK",
         "mutability":"MUTABLE",
         "data":{
            "url":"http://fosadofle.com/",
            "href":"http://fosadofle.com/"
         }
      },
      "7":{
         "type":"LINK",
         "mutability":"MUTABLE",
         "data":{
            "url":"http://fosadofle.com/",
            "href":"http://fosadofle.com/"
         }
      }
   },
   "blocks":[
      {
         "depth":0,
         "type":"unstyled",
         "text":"Test one",
         "entityRanges":[
            {
               "offset":5,
               "length":3,
               "key":6
            }
         ],
         "inlineStyleRanges":[

         ]
      },
      {
         "type":"unstyled",
         "text":"",
         "entityRanges":[

         ],
         "inlineStyleRanges":[

         ]
      },
      {
         "depth":0,
         "type":"unstyled",
         "text":"Test two",
         "entityRanges":[
            {
               "offset":5,
               "length":3,
               "key":7
            }
         ],
         "inlineStyleRanges":[

         ]
      }
   ]
}

@Leonarto
Copy link
Author

Leonarto commented Jun 5, 2020

Hi!, I'm sorry for taking so long. And you are totally right, I found out recently that this corner case error needs more conditions, is whenever you have a unicode emoticon in the same line, like this example raw object.

In this example the middle link will translate fine while the one at the end of the line won't:

const exampleRawObject = {
  "blocks": [{
    "key": "eubc2",
    "text": "🙋 link link",
    "type": "unstyled",
    "depth": 0,
    "inlineStyleRanges": [],
    "entityRanges": [{"offset": 2, "length": 4, "key": 0}, {"offset": 7, "length": 4, "key": 1}],
    "data": {}
  }],
  "entityMap": {
    "0": {
      "type": "LINK",
      "mutability": "MUTABLE",
      "data": {"url": "https://link.com", "href": "https://link.com"}
    }, "1": {"type": "LINK", "mutability": "MUTABLE", "data": {"url": "https://link.com"}}
  }
}

@Rosey
Copy link
Owner

Rosey commented Jun 6, 2020

Ah fantastic thank you! I've encountered similar bugs in the past with strings so I think I know what the problem might be :) (string length issues as outlined in this article https://mathiasbynens.be/notes/javascript-unicode)

Rosey pushed a commit that referenced this issue Jun 10, 2020
@Rosey
Copy link
Owner

Rosey commented Jun 10, 2020

I've opened #123 to address this issue, will leave open for a day or two as an RFC from anyone interested before merging and releasing the fix 🙂

@Rosey
Copy link
Owner

Rosey commented Jun 10, 2020

Thanks for the report!! 🎉

@Leonarto
Copy link
Author

Amazing!, thanks to you on your good will!

@Rosey Rosey closed this as completed Jun 14, 2020
@igor-sysoev
Copy link

Hi, I think this issue is still relevant in the latest version. I haven't been able to replicate it yet, but as far as I understood it seems to happen when you have two links next to each other.

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

No branches or pull requests

3 participants