Rosey/markdown-draft-js

Quirk in handling of mixed bold and italics in a single word

Opened this issue · 1 comments

First up, I just wanted to say thanks for this project and especially for making the interactive demo of it so easily available. It looks like it's going to be a big help for me. It seems to have much better support for escaping markdown special characters than some alternatives I've also tried, which sets it apart. Also, thanks for setting expectations on turnaround for any discussion or a fix. I know that these are highly unusual times and would not ever want to cause any distress by this, so please only respond if or when you feel able to do so comfortably.

That said, I was playing around with the interactive tool and noticed a seemingly small quirk in the way bold and italics are handled that I can reproduce reliably:

  1. In the draftjs editor, type the single word "boldbothitalics" (it doesn't matter what you type, but this is demonstrative)
  2. Highlight the 'bothitalics' portion, and apply italics using the draft editor's button
  3. Highlight the 'boldboth' portion, and apply bold using the draft editor's button
  4. Note that the markdown produced is: **bold_both_**_italics_

image

  1. Add a space to the end of the markdown, presumably triggering an import back into the draftjs editor component
  2. Note that the formatting in the draftjs editor has been corrupted:

image

Manually entering the following markdown seems to generate the correct formatting in the draftjs editor however: __bold__***both***_italics_

image

I'm not sure if this is a hard fix or an easy one, but I thought I'd record it here since I found a good way to reproduce.

(As a side note, I'll also mention that GitHub themselves seem to have a very similar issue generating correct markdown for this formatting. That suggests this might be a tough problem. If you use the formatting buttons in the GitHub editor to create boldbothitalics, you end up with the following markdown: **bold_both**italics_ which renders as bold_bothitalics_.)

Rosey commented

Nice, thank you for the detailed report and kind words! I'll take a look when I have a chance, seems worth investigating ♥️