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

Newlines in WYSIWYG are not correctly converted to markdown #1347

Open
karelbilek opened this issue Jan 19, 2021 · 5 comments
Open

Newlines in WYSIWYG are not correctly converted to markdown #1347

karelbilek opened this issue Jan 19, 2021 · 5 comments
Labels

Comments

@karelbilek
Copy link

karelbilek commented Jan 19, 2021

Describe the bug

When newline is in WYSIWYG mode inside a paragraph, it's not converted correctly to Markdown

To Reproduce

(note: this will be a bit hard to read due to Markdown's use of whitespace)

Steps to reproduce the behavior:

  1. Go to https://nhn.github.io/tui.editor/latest/tutorial-example03-editor-with-wysiwyg-mode
  2. delete everything, switch to "WYSIWYG"
  3. add the following, in wysiwyg mode
foo bar
foo bar

That is - foo<space>bar<newline>foo<space>bar

  1. Click "markdown"

Expected behavior

See:

foo bar<space><space>
foo bar

Actual behavior

See:

foo bar
foo bar

Note that this is not actually visible, as you cannot see the whitespaces, but it differs on what is actually there.

Desktop (please complete the following information):

Replicable everywhere

Additional context

Newline in Markdown inside a paragraph should NOT trigger a newline. So, foo<space>bar<newline>foo<space>bar in Markdown should render as foo<space>bar<space>foo<space>bar.

This editor does not follow this.

So, when user enters, into WYSIWYG

foo bar
foo bar

(without the spaces)

and then, we save the Markdown from the editor and use a different, but CommonMark compliant, parser and renderer, it gets rendered incorrectly.

@karelbilek karelbilek added the Bug label Jan 19, 2021
@karelbilek
Copy link
Author

I think unfortunately, fixing this might not be backwards compatible :/ as some user might actually depend on this functionality. That a<space>b<newline>c<space>d renders same in HTML.

@karelbilek
Copy link
Author

I noticed goldmark, which is our Go renderer on backend, has option goldmark.WithRendererOptions(html.WithHardWraps()) that solves this on BE side.

@karelbilek
Copy link
Author

karelbilek commented Jan 19, 2021

https://spec.commonmark.org/0.29/#hard-line-breaks
https://spec.commonmark.org/0.29/#soft-line-breaks

I see "A renderer may also provide an option to render soft line breaks as hard line breaks", but I don't see if you provide such an option? (If you do, it's on by default :D )

@seonim-ryu
Copy link
Member

seonim-ryu commented Jan 20, 2021

@karelbilek I think the problem you are talking about is because the soft brake works like a hard brake. First of all, the Editor follows the CommonMark specification, but because of the compatibility between Markdown and WYSIWYG editors, newline is treated as a hard break. This is the Editor's spec.

In the Markdown's preview, the rendering of soft breaks and hard breaks can be handled using custom HTMLRenderer. However, converting or not generating <br> can be solved in v3.0. Please refer to the issues below.

#485

@bkis
Copy link

bkis commented Mar 10, 2022

What I think is even worse: If you break the line like this in Markdown mode:

foo<space><space>
bar

... and then switch to WYSIWYG, it changes the actual Markdown to:

foobar

... removing the line break (and the spaces) completely!

This is a huge problem, because if you load existing Markdown content (that was not created in the editor in the first place) that uses the two trailing spaces before the line break, the editor completely destroys those line breaks!
I am working on a project where we make a big collection of existing Markdown files editable by the users. Those files use the trailing spaces before line breaks. Each time a document is loaded into the editor, all the line breaks are destroyed 😮‍💨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants