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

#2512 - Fix a couple of chat regressions #2521

Merged
merged 6 commits into from
Jan 20, 2025

Conversation

SebinSong
Copy link
Collaborator

closes #2512

[ screenshot for the fix ]

image

@SebinSong SebinSong self-assigned this Jan 18, 2025
Copy link

cypress bot commented Jan 18, 2025

group-income    Run #3768

Run Properties:  status check passed Passed #3768  •  git commit e9685cad4f ℹ️: Merge fe1e33e33eeb9f1984baa4f2c9a76c31012a71c6 into f98136959f311764d9af8d030995...
Project group-income
Branch Review sebin/task/#2512-chat-issues
Run status status check passed Passed #3768
Run duration 10m 50s
Commit git commit e9685cad4f ℹ️: Merge fe1e33e33eeb9f1984baa4f2c9a76c31012a71c6 into f98136959f311764d9af8d030995...
Committer Sebin Song
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 112
View all changes introduced in this branch ↗︎

Comment on lines -43 to -54
entryText = entryText.replace(/\n(?=\n)/g, '\n<br>')
.replace(/<br>\n(\s*)(>|\d+\.|-)/g, '\n\n$1$2') // [1] custom-handling the case where <br> is directly followed by the start of ordered/unordered lists
.replace(/(>|\d+\.|-)(\s.+)\n<br>/g, '$1$2\n\n') // [2] this is a custom-logic added so that the end of ordered/un-ordered lists are correctly detected by markedjs.
.replace(/(>)(\s.+)\n<br>/gs, '$1$2\n\n') // [3] this is a custom-logic added so that the end of blockquotes are correctly detected by markedjs. ('s' flag is needed to account for multi-line strings)

// GI needs to keep the line-breaks in the markdown but the markedjs with 'gfm' option doesn't fully support it.
// So we need to manually add <br/> tags here before passing it to markedjs.
// (Reference: https://github.com/markedjs/marked/issues/190#issuecomment-865303317)
entryText = entryText.replace(/\n(?=\n)/g, '\n\n<br/>\n')
entry.text = entryText
}
})

str = combineMarkdownSegmentListIntoString(strSplitByCodeMarkdown)
str = str.replace(/(\d+\.|-)(\s.+)\n<br>/g, '$1$2\n\n')
.replace(/(>)(\s.+)\n<br>/gs, '$1$2\n\n') // Check for [2], [3] above once more to resolve edge-cases (reference: https://github.com/okTurtles/group-income/issues/2356)
Copy link
Collaborator Author

@SebinSong SebinSong Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give a context here, these multiple lines of regExp logics to manually add <br> here had been added over time to resolve issues related to multiple line-breaks in the chat. (markedjs with 'gfm' option does not support the behavior we want. eg. we would want \n\n\n to become <br><br><br> but it collapses them all and convert to a single <br> or sometimes even removes them all)

I re-assessed these part and enhanced/simplified as much as I could because it had been growing in complexity over time, which made it hard to maintain. I made sure this change doesn't break the previous issues we fixed before:

[Complex markdown structure 1 - nested lists]

image

[Complex markdown structure 2 - blockquotes]

image

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work @SebinSong!

I think you got almost everything!

I did some tests and it seems there may still be an issue in how newlines are handled in blockquotes.

Have a look at this:

Hello https://asdf.com https://okturtles.org

> This is a test
> Of the https://asdf.com https://okturtles.org system
> 
> Does it work?
> () => Does it actually work? <>
> <adsf>asdf</asdf>
> 
> ```js
> hello
> ```
> 1. asdf
> 2. sadfasdf https://asdf.com https://okturtles.org/1111 😜👍
> 3. https://asdf.com https://okturtles.org
>    1. Is this really 1234 working? #general you tell me @u1!
>        ```
>        does it?
>        ```

- It seems not always
- Another test

Which renders on GH like this:


Hello https://asdf.com https://okturtles.org

This is a test
Of the https://asdf.com https://okturtles.org system

Does it work?
() => Does it actually work? <>
asdf

hello
  1. asdf
  2. sadfasdf https://asdf.com https://okturtles.org/1111 😜👍
  3. https://asdf.com https://okturtles.org
    1. Is this really 1234 working? #general you tell me @U1!
      does it?
      
  • It seems not always
  • Another test

And in GI like this:

Screenshot 2025-01-18 at 10 40 10 AM

I am actually OK with #general or @u1 not rendering deep within blockquotes. It's not the end of the world.

However, the fact that this section is rendered incorrectly is a serious issue:

> Does it work?
> () => Does it actually work? <>
> <adsf>asdf</asdf>

It should be broken up across 3 lines, but GI breaks it up across 2 lines.

@SebinSong
Copy link
Collaborator Author

SebinSong commented Jan 20, 2025

@taoeffect
Fixed both issues you pointed out:

image


One thing I noticed in your comment was that GI comment also seems to have the rendering issue too (Or, could be an expected behavior for their markdown convertor):

[ Input ]



[ Output - Some texts disappear ]
Apparently <asdf>asdf</asdf> is interpreted as an illegal html and sanitized.



And below is the raw conversion output from markedjs. (check out this markedjs playground)



which is where you can see the same issues happening too. It does not even support multiple line-breaks in a row, as mentioned before.


What I want to mention here is, The amount of custom logics to override/fix these default behaviors created by markedjs are quite large at this point so it feels quite hard and tricky to maintain these area now.
(Eg. Trying to fix one issue introduces regressions for previous fixes etc.)
So, I'm worried if we would try to add more custom behaviors in the future, that might make the code harder to manage. Just something I felt while working on the updates. Thanks.

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work @SebinSong!

What I want to mention here is, The amount of custom logics to override/fix these default behaviors created by markedjs are quite large at this point so it feels quite hard and tricky to maintain these area now.
(Eg. Trying to fix one issue introduces regressions for previous fixes etc.)
So, I'm worried if we would try to add more custom behaviors in the future, that might make the code harder to manage. Just something I felt while working on the updates. Thanks.

Indeed. If you think of a better way to solve this, e.g. maybe switching to a different library, or maybe diving more into markedjs' capabilities (if any such capabilities exist), feel free to open an issue.

@taoeffect taoeffect merged commit cb101e5 into master Jan 20, 2025
4 checks passed
@taoeffect taoeffect deleted the sebin/task/#2512-chat-issues branch January 20, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chat regressions on master related to list spacing and emoji span
2 participants