portive / wysimark

The Wysiwyg Editor for Markdown: 100% CommonMark + GFM with Uploads and Image Resizing
Other
236 stars 41 forks source link

setMarkdown() Removes multiple new lines #46

Closed CodyCodes95 closed 1 year ago

CodyCodes95 commented 1 year ago

Description When running saveMarkdown() If you have multiple enters in the editor, the markdown will be saved correctly. For example: "Three New lines up ahead \n\n\n That is three new lines".

However if you load the editor with that same string, those new lines get removed.

I want to use this for spacing. If this is not the way to do it, how can we have user submitted spacing between paragraphs? Hitting enter as many times as you want seems the most intuitive.

Reproduction

https://github.com/portive/wysimark/assets/94301860/8124114e-c6ce-44fb-a1a4-345dac01c283

Steps To reproduce the behavior:

  1. Type a paragraph into Wysimark
  2. Spam enter n amount of times
  3. Save text using getMarkdown()
  4. See the saved text has multiple \n characters
  5. Reload the editor with your saved text as the value
  6. Multiple new lines are now gone

Expectation Expect to have the new lines remain when you load them in the initial markdown.

Environment

thesunny commented 1 year ago

@CodyCodes95 Thanks for the issue submission. Markdown doesn't have a natural way of encoding blank paragraphs because it collapses them together; however, we may be able to use a workaround where we encode a blank paragraph with " " (non breaking space).

May I ask how critical this is to your application at the moment? Thanks.

thesunny commented 1 year ago

@CodyCodes95 This issue should now be resolved in 3.0.20

Consecutive paragraphs are saved as "\n\n \n\n". Technically, a non-breaking space is being inserted into the Markdown and visually we just see the extra space. When Wysimark reads that Markdown into the editor, it will recognize this as an empty paragraph and the paragraph in the editor will not include a non-breaking space which may cause weird behavior in the editor to the end user.

CodyCodes95 commented 1 year ago

@thesunny You're the man! Appreciate this. Thankyou