mattermost / mattermost

Mattermost is an open source platform for secure collaboration across the entire software development lifecycle..
https://mattermost.com
Other
30.52k stars 7.32k forks source link

Bug: Extra blank lines inserted in code blocks #22891

Open 3kami3 opened 1 year ago

3kami3 commented 1 year ago

Summary

The bug is that extra blank lines are inserted when lists (1.,2.,3.,,) and code blocks (```) are used together.

Steps to reproduce

VERSIONS

mattermost/mattermost-team-edition:7.9.1

OPARATION

Enter the following markdown code block as a message input.

1. test
```patch
1

3

Languages are reproduced not only in 'Diff(patch)' but also in 'Bash', etc.

#### Expected behavior
More unnecessary blank lines.

#### Observed behavior (that appears unintentional) 
No more unnecessary blank lines.
This bug affects not only the display but also the copy code.
Copying and pasting the patch code is an unexpected error factor.
<img width="458" alt="mm123" src="https://user-images.githubusercontent.com/12627100/230610237-57d9528f-5624-4f5b-b220-0524285af983.png">
<img width="458" alt="mm1_3" src="https://user-images.githubusercontent.com/12627100/230610259-048195a6-4506-4fe5-924d-fa4882444049.png">
amyblais commented 1 year ago

Opened https://mattermost.atlassian.net/browse/MM-52081.

sugamadhiakri commented 1 year ago

@amyblais could you assign this issue to me?

sinansonmez commented 1 year ago

@sugamadhiakri are you still working in this issue?

adityasoni2019 commented 3 weeks ago

Can I take this up? @amyblais

adityasoni2019 commented 1 week ago

Hey @amyblais, It seems to me like there's some issue with how the text is parsed by the "marked" library for markdown content.

As you can see in the below file -

image

the output is - '1. test\npatch\n1\n\n3\n' (which is fine, cause it has 1 new line b/w 1 & 3 - 1 & 3)

but, as soon as the Makrdown.format() function is called (which is calling some functions that have input given by the markdown lib at some point in it's journey), the output changes to -

image

Which has 2 lines in b/w 1 & 3

See below how the code function is called with - '1\n\n\n3' (2 lines b/w 1 & 3; and this input has been I think given by the markdown file)

image

So, if there's any dev that has some perspective on this, that'd be great!

Thanks!

Edit: Marked library link - https://marked.js.org/

amyblais commented 1 week ago

It seems to me like there's some issue with how the text is parsed by the "marked" library for markdown content. . . .

@3kami3 Feel free to come join our "Contributors" community channel on the Mattermost Community server, where you can discuss questions with community members and the Mattermost core team. For technical advice or questions, please join our "Developers Server" community channel.

hmhealey commented 5 days ago

@adityasoni2019 Great find there. I would've expected that the bug would've been something with how we render the code block, not in the Markdown code itself.

We actually use a heavily modified fork of Marked, so perhaps there's something we've changed which is making that happen? The code for that is here: https://github.com/mattermost/marked

hmhealey commented 5 days ago

Taking a quick look through that, I noticed this commit where I made some changes to how whitespace in code blocks are handled:

https://github.com/mattermost/marked/commit/cd82cf9e4d1b1a8bcfc1389e9d2f13ac7800e541

That sounds like it could be related to this issue. It was a fix for https://github.com/mattermost/mattermost/issues/6865

adityasoni2019 commented 3 days ago

Thanks for looking into it, @hmhealey. I was wondering if there's a way to put debuggers on the marked library codebase, while running my mattermost/mattermost? If not, any recos on how to debug it?

Edit: Also, for checking if my changes on the marked lib have resolved the bug I can just change this line (in package.json) according to my personal fork, right? -

"marked": "github:mattermost/marked#2ef7f28cc7718e3f551c4ce9ea75fdd7580c2008",