[BUG] Extraneous newlines truncated on load
rbbydotdev opened this issue · comments
- I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- I have read the documentation and cannot find an answer.
Describe the bug
Initializing the editor with a markdown document with extraneous newlines, will automatically truncate the newline, thereby making a diff for the document /changing the document
Reproduction
The following will be truncated
# Heading
becomes
# Heading
To Reproduce
Initialized the editor with the first example with extraneous newlines, either check the document with the diff plugin, or monitor the gurx signals
Expected behavior
Expecting the newlines to remain.
Screenshots
None
Desktop (please complete the following information):
- Macos
- Firefox
The trimming of the markdown is intentional, but I can see how this can cause problems. I might consider changing this in a future version or introducing a prop to control it.
@RokasAnisas this is not the same issue, markdown does this by design.
@petyosi What would be your recommended way to add multi-newlines?
Saved as:
Hello\n\n\nWorld
Rendered as:
Hello
World
I faced same issue. How to fix?
I faced same issue. How to fix?
At this point I am considering moving over to a different component.
The trimming of the markdown is intentional, but I can see how this can cause problems. I might consider changing this in a future version or introducing a prop to control it.
@RokasAnisas this is not the same issue, markdown does this by design.
This is a bad representation of the problem with the screenshots that I've provided, it was just for illustration, the other users that have commented on this issue with are more accurate
Hello\n\n\nWorld
Regardless, getting the same result, line breaks are removed, even thought the same string
opened as a markdown
document does indeed display those line breaks
@petyosi - Is there something happening within mdast? I haven't looked at the source but I am suspecting it's because mdx-editor is parsing to a tree and outputting again to markdown; am i correct in that assumption? If there were some way to reach into this and modify that process, could be more elegant than just adding an option.
Having the same issue, markdown renderers (such as react-markdown) are picking up the new lines but the editor isn't.
Super weird that one can add new lines with the editor but they aren't picked up on load.
I think I found a similar issue/workaround .
This behavior was creating diff issues with content generated in the editor itself.
Consider this example:
- Open a blank editor
- Write
Line 1
- Press
Enter
- Press `Enter
- Write
Line 2
If getting the value with the onChange(value)
callback the value is equal to: Line 1\n\n\n\nLine 2
=> this will trigger a diff issue when pasting back into the editor.
However, using editorRef.current.getMarkdown()
returns the trimmed content Line 1\n\nLine 2
=> this will not trigger a diff issue.
So I'm using getMarkdown() to save the contents now, of course the file will look different when reopening but that's just how Markdown works.
I'm facing the same issue. This will not be fixed? Because if not, does not make any sense enable the users to do paragraphs.
Is there any update?
I have already replied #639 (comment). If someone wants to contribute an option that prevents the trimming of the whitespace in the beginning/end of the string, I'm happy to accept a PR.
The other issue is by markdown design.
Locking this to avoid getting notifications from "any updates?".