-
Notifications
You must be signed in to change notification settings - Fork 94
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
Remove trailing newline from code blocks #3321
Conversation
1a449e7
to
74ec9e9
Compare
f29c0ca
to
ced0ada
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for the fix 🥳
This breaks the common mark tests as
is expected to render to
But generally the last I noticed that sometimes a new line is added visually (but not in the markdown). I do not know why, but prosemirror adds sometimes a |
You're right. I broke commonmark on purpose in this case because the linebreak before closing HTML tags seems to cause ProseMirror to add the HTML break element. But I forgot to disable/edit the respective commonmark tests. With my changes, the newline doesn't get added anymore. Another solution would be to find out why ProseMirror adds the break element, but to be honest for me it was an acceptable tradeoff to break commonmark because I don't see a reason to have a linebreak before the closing HTML tags, but maybe I'm missing something? Would you prefer another solution @susnux? |
But it does not always add the newline, and the newline is only added visually, so are you sure it does not appear anymore? |
So after some further debugging, my understanding is that I'm not sure yet why the break tag is only added sometimes by prosemirror-view, but at least this PR reproducibly fixes the issue for me. Whenever a newline is added to the end of a code block, this is reproducible for the same document. Closing the document, resetting the Text session and opening the document again reliably adds the new line again to the same code blocks where it's been added before. And everytime, applying the PR in between removes the newline. |
ced0ada
to
06a08a5
Compare
06a08a5
to
8fd57c3
Compare
After digging into this again with @juliushaertl I went with another approach. So first, it's reproducible that the newline from markdown-it results in the rendered extra newline in Tiptap. Everytime you close the editor, reset the session and open the editor again, the trailing newline is back. So that means that we can assume the HTML as given from markdown-it always contains one trailing newline too much. That's why I went with removing one trailing newline from the code block content in |
8fd57c3
to
be3a2e2
Compare
Markdown-it serialized code blocks to `<pre><code>...\n</pre></code>`, which leads to trailing newlines in the code blocks as rendered by Tiptap. Let the Tiptap CodeBlock node remove the trailing newline in parseHTML in order to avoid this. There's another issue with trailing newlines that got added to code blocks on purpose being removed by prosemirror-markdown, but that's not affected by this change. Fixes: #2344 Signed-off-by: Jonas <jonas@freesources.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small debugging leftover, otherwise 👍 as discussed :)
be3a2e2
to
e78f78f
Compare
/compile |
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
/backport e78f78f to stable25 |
The backport to stable25 failed. Please do this backport manually. |
Markdown-it serialized code blocks to
<pre><code>...\n</pre></code>
, which leads to trailing newlines in the code blocks as rendered by Tiptap.Let the Tiptap CodeBlock node remove the trailing newline in parseHTML in order to avoid this.
There's another issue with trailing newlines that got added to code blocks on purpose being removed by prosemirror-markdown, but that's not affected by this change.
Fixes: #2344
Signed-off-by: Jonas jonas@freesources.org
Summary