Closed pauloptimizely closed 5 years ago
Thank you for contributing and I'm glad you're finding the library useful!
I'll take a more detailed look soon but one question:
This feature is useful, in the case where saving markdown to a database is desired.
Just to confirm that you realize this means that both rich formatting in the wyiwyg and plain characters typed by the user in the wysiwyg will both be interpreted as markdown? And then when being converted BACK to draft it will all be rich-text? And that's the behavior you want?
Thanks for taking a look Rosey! :)
To answer your questions, yes, that's correct! having both wyiwyg and plain characters interpreted as markdown is the desired behavior
And then when being converted BACK to draft it will all be rich-text?
This is also ideal!
Cool! I think code-wise this looks good, my only thoughts are around naming and documentation.
Curious for your input (or anyone else's)
💡 My (tentative!) suggestion:
escapeMarkdownCharacters
might be a better fit? Have it default to true
and require the user to pass in false
? I am not sure about this but my concern is the current naming might be confusing for people as to what it does.
Possible README change -
escapeMarkdownCharacters
– by default this value is true and markdown characters (e.g. *~_`) typed directly into the editor by a user are escaped when converting from draft to markdown.Setting this option to false will prevent those special characters from being escaped, so the markdown string it generates will remain in its “raw” form. What this means is that when the markdown is later converted back to draftjs or parsed by a different markdown tool, any user-entered markdown will be rendered AS markdown, and will not "match" what the user initially entered. (So if the user explicitly typed in
**hello**
, converting to markdown and back to draft it will be restored as hello instead of the original **hello**)
(By the way if you're happy with this change or have any amendments or whatever, after we're done discussing I'm fine with making the changes myself, I don't want to put any undue burden on you because of my change requests!)
Call good!! I like escapeMarkdownCharacters
, it's much more descriptive. I'll push an update with that change, as well as, the updated documentation.
Thank you!! I'll do a release soon :)
Thanks Rosey!!:)
:) sorry if you're waiting! It will probably be tonight, was busy with childcare last night and I'm out of the house all day today hiking and visiting friends.
@Rosey No worries!! It's no rush, have fun hiking that sounds awesome!
Summary
This PR adds an option to prevent escaping special markdown characters (i.e
\*|_|~|\\|
) when converting from draft to markdown.When
preserveMarkdown
is set totrue
the generated markdown string will be in its "raw" form, with no escaped characters. This feature is useful, in the case where saving markdown to a database is desired.The code changes in this PR are meant to be backwards compatible with the existing API. So the
draftToMarkdown
function will behave as normal when thepreserveMarkdown
flag is not set.Let me know if you have any questions or concerns about these code changes.
p.s. Thanks for creating this awesome library!!:) It's been lifesaver!
Test Plan
Run the test suite to ensure all tests pass