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

Outputs incorrect markdown #10

Open
Jpunt opened this issue Oct 4, 2017 · 4 comments
Open

Outputs incorrect markdown #10

Jpunt opened this issue Oct 4, 2017 · 4 comments

Comments

@Jpunt
Copy link

Jpunt commented Oct 4, 2017

Let's assume a user starts typing, enables bold, types some more words (and ends with a space).

As soon as the user disabled bold, this results in invalid markdown:

some words before bold, **some words in bold **and some words after bold

The space after the word bold should be placed after the two stars instead of before them, or it'll result in a plain text (containing the stars themselves).

Edit: This issue also happens a lot sooner:

  • Enable bold
  • Type a word
  • Type a space

This will result in **word **, instead of the word in bold.

@jpuri
Copy link
Owner

jpuri commented Oct 24, 2017

Thanks for reporting this @Jpunt , I will try to fix this soon.

@link2malkeet
Copy link

hi @jpuri is there any plan to fix this?

@nhevia
Copy link

nhevia commented Jan 26, 2022

Having this issue as well and it's not an issue with this library, but something that is carried from react-draft-wysiwyg. Let me explain (following the same example as OP)

  1. Typed before bold
  2. Typed bold and applied bold style
  3. Disabled bold style and typed no bold
    Results in: before bold **bold ** no bold.

As it can be seen from editorState (from react-draft-wysiwyg), the length of style is incorrect (should be 4).
image

Since this issue is 4 years old, I thought about patching the diff. But the issue is that copy-pasting the text (which leaves it unstyled) and then applying style to the bold word, this is the result:

image

Which is now correct and substracting the lenght would apply bold style to only a substring of the word.

Edit: on top of this, combining styles with emojis will break it even further and emojis will appear as � icons (might be related to this

@nhevia
Copy link

nhevia commented Jan 27, 2022

#43 as a workaround, to make it work directly from this library. It's based in two proposals:

  1. Trims to reduce the incorrect length, if any. Have to be careful before the style characters were applied around whitespaces. One thing to note, this happens for ALL styles, not only bold. Correct:
asd *asd* asd
asd **asd** asd
asd __asd__ asd
asd ~~asd~~ asd
# **asd asd asd**
- **asd**
  1. Delete style is block has any emoji altogether. Unrelated to this particular issue and very opinionated, but better than showing random symbols instead of emojis.

***😇😈�***�💪😺 -> 😇😈👸💪😺

This fix is applied to https://www.npmjs.com/package/@nhevia/draftjs-to-markdown because I need this fix ASAP and they don't look like moving a lot. But if PR is merged I'll go back to this lib.

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

4 participants