Rosey / markdown-draft-js

A tool to convert content created in DraftJS to markdown and vice versa.
https://rosey.github.io/markdown-draft-js/
MIT License
318 stars 69 forks source link

Draft-to-markdown needs to escape special characters #52

Closed ckoppelman closed 6 years ago

ckoppelman commented 6 years ago

If I enter _abc_ into the draft editor, I'd expect to see the Markdown editor have \_abc\_.

There are a set of similar test cases:

  1. * sdfsfsf => \* sdfsfsf
  2. abc **sdasda** => abc \*\*sdasda\*\*
  3. 4. abc => 4\. abc
  4. c `abc` d => c \`abc\` d
  5. > sdfjsflsdkfj => \> sdfjsflsdkfj
  6. \abc => \\abc
Rosey commented 6 years ago

Thank you for pointing this out! Will prioritize a fix.

I've never noticed this because I use a markdown plugin on my draft editor that auto-converts to italics etc when you use those characters, so it never has come up for me 😄

nicholaswbowen commented 6 years ago

This would be great to have built in, I'm currently escaping them just before they get converted.

On Fri, May 11, 2018, 11:04 AM Rose notifications@github.com wrote:

Thank you for pointing this out! Will prioritize a fix.

I've never noticed this because I use a markdown plugin on my draft editor that auto-converts to italics etc when you use those characters, so it never has come up for me 😄

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Rosey/markdown-draft-js/issues/52#issuecomment-388441061, or mute the thread https://github.com/notifications/unsubscribe-auth/AWSGaPn8NE9_Yk6bRg9IJhmV7GPk9k9dks5txdLIgaJpZM4T7zsh .

ckoppelman commented 6 years ago

By the way, I just learned the proper way to escape backticks in inline code spans -- it's not backslashes.

Apparently you just need to use different numbers of backticks at the start and end of your code. So if you have a single backtick literal inside your code span, you need to start/end with at least two backticks. If you have two backtick literals together inside a code span, you need to use one or three or more backticks to start/end your code span. If you have single, double and triple backtick literals inside your code span, you need to use at least four backticks to start/end your code span.

Gah!

Rosey commented 6 years ago

Lol yay

Rosey commented 6 years ago

Ok I have a branch going but I don't think it's comprehensive enough yet to open a pr

Rosey commented 6 years ago

ahh, opened a pr. I can't even describe to you how messed up I am these days, last night I only got 4 hours of sleep, so... yep. I guess if I were a good nerd I'd just wait to fix bugs until I can actually do it properly but lmk how you feel about this fix. I'll merge it if @ckoppelman and @nicholaswbowen are ok with it as an interim solution?

nicholaswbowen commented 6 years ago

This is a good interim solution. I hope to make some contributions some time soon, maybe I'll take a crack at this. For my use case, people posting links into the editor is very common. That PR will let me delete code atleast :) . Thanks!

Rosey commented 6 years ago

For my use case, people posting links into the editor is very common.

Just out of curiosity - if people are posting [link](http://google.com) ...why on earth are they pasting such specific markdown code and NOT wanting it converted? Like I can see how benign characters like * and _ that could have other meanings shouldn't be converted, but links are so very markdowny

Rosey commented 6 years ago

Made a new issue for some of the outstanding work that needs to be done :) https://github.com/Rosey/markdown-draft-js/issues/55 Thank you to both of you!

nicholaswbowen commented 6 years ago

Oh, I think I misunderstood what you meant. I don't imagine many people would use the link syntax in the draft editor.

What my problem is that I am serializing everything as Markdown, and comments get rendered in remarkable. So if URLs have any of the escaped characters in them, it breaks the link when it gets rendered. What I am suggesting is a regex expression that detects something as simple as https://google.com and doesn't escape any of the characters in that string. Then remarkable will just linkify them and I have happy customers.

I hope that makes sense. Thanks again!