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

refactor: Improve linebreak logic for html messages #2022

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

krille-chan
Copy link
Contributor

@krille-chan krille-chan commented Feb 6, 2025

Closes #1691

Tested in FluffyChat:

image

@krille-chan krille-chan marked this pull request as ready for review February 6, 2025 14:00
@krille-chan krille-chan requested a review from a team as a code owner February 6, 2025 14:00
@krille-chan krille-chan force-pushed the krille/fix-linebreaks-in-html-messages-correctly branch from 3abfc9b to 552881d Compare February 6, 2025 14:05
text = text
.trim()
.split('\n')
.map((line) => line.isEmpty ? '\u200C' : line)

Choose a reason for hiding this comment

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

You can not used this symbol as workaround because it used in Persian alphabet
https://en.wikipedia.org/wiki/Zero-width_non-joiner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about the zero width space character U+200B then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to marking it with a newly defined /newline marker. This gets ignored in markdown itself. The only side effect would be, that the user could type /newline everywhere which would be converted to a normal linebreak

@krille-chan krille-chan force-pushed the krille/fix-linebreaks-in-html-messages-correctly branch from 552881d to d255b8b Compare February 6, 2025 15:06
@krille-chan krille-chan force-pushed the krille/fix-linebreaks-in-html-messages-correctly branch from d255b8b to c75c1cd Compare February 7, 2025 07:22
@krille-chan krille-chan force-pushed the krille/fix-linebreaks-in-html-messages-correctly branch from c75c1cd to 2446740 Compare February 7, 2025 08:27
// in all empty lines to keep the lines as the user added them and workaround
// the markdown rules for multiple empty lines.
text = text
.replaceAll('/newline', '\n')
Copy link
Member

Choose a reason for hiding this comment

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

This feels very hacky, what if people send /newline/newline/newline or so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then they will have three new lines. I thought as we support commands with /anything anyway this is the best compromise. We already wasted countless hours to find a non hacky solution and havent found one

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.

Don't trim double newlines
3 participants