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

Preserve newlines in plain text messages #388

Merged
merged 2 commits into from
Oct 19, 2022

Conversation

n-peugnet
Copy link
Contributor

New lines were not displayed in plain text messages. There might be a better way, but I choose to manually convert the newline characters into BreakEntities inside of a ContainerEntity.

I didn't use my new function for the value of a plan text link, as it must not contain any new lines.

Demo

Event

{
  "room_id": "!***:matrix.org",
  "type": "m.room.message",
  "content": {
    "org.matrix.msc1767.text": "Probablement que j'ai pas répondu alors 😅\nMerci pour le partage mais je suis pas chaud pour y aller",
    "body": "Probablement que j'ai pas répondu alors 😅\nMerci pour le partage mais je suis pas chaud pour y aller",
    "msgtype": "m.text"
  }
}

Before

2022-10-10-201655_849x77_scrot

After

2022-10-10-201934_807x92_scrot

@@ -388,16 +388,39 @@ func (parser *htmlParser) tagNodeToEntity(node *html.Node) Entity {

var spaces = regexp.MustCompile("\\s+")

// textToHtmlEntity converts a plain text string into an HtmlEntity while preserving newlines.
func textToHtmlEntity(text string) Entity {
Copy link
Owner

Choose a reason for hiding this comment

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

@tulir tulir merged commit 71f16b7 into tulir:master Oct 19, 2022
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.

2 participants