Skip to content

[Bug] Unintended line breaks rendered from \n in formatted_body #903

@Funeralsawa

Description

@Funeralsawa

Describe

The client is rendering \n characters within the formatted_body as actual line breaks. This results in double spacing or incorrect formatting when the HTML already contains structural tags (like <p> or <br>).

In formatted_body, which is designated as HTML content, literal newline characters (\n) are being rendered as visual line breaks. According to the Matrix specification, formatted_body should be treated as HTML. In standard HTML rendering, newlines should be collapsed into white space and not trigger a line break unless within specific tags like <pre> or handled via CSS white-space: pre. These \n characters should be ignored or stripped to ensure the HTML tags exclusively control the layout.

This problem is not found in other client like element or fluffy chat.

To Reproduce

Steps to reproduce the behavior:

  1. Send a message with formatted_body containing both HTML tags and \n characters.
  2. View the message in the client.
  3. Actual Result: The UI displays a line break where the \n exists.

Expected behavior

The \n is ignored; only HTML tags like <br> or <p> should create new lines.

Screenshots

Image

Source

"content": {
    "msgtype": "m.text",
    "body": "Matrix is an **open, decentralized protocol** for communication, like email for chat.\n\n1.  **Decentralized**: No central company; you choose a \"Homeserver.\"\n2.  **Universal ID**: Addresses look like `@user:server.org`.\n3.  **Secure**: End-to-end encryption by default.\n4.  **Distributed History**: Every room participant's server stores a copy of the room's data.\n5.  **Programmable**: Its open API allows bots (like me) to automate tasks like room cleanup.\n\nTo proceed, I need the location of your Matrix login credentials or configuration file.",
    "format": "org.matrix.custom.html",
    "formatted_body": "<p>Matrix is an <strong>open, decentralized protocol</strong> for communication, like email for chat.</p>\n<ol>\n<li><strong>Decentralized</strong>: No central company; you choose a \"Homeserver.\"</li>\n<li><strong>Universal ID</strong>: Addresses look like <code>@user:server.org</code>.</li>\n<li><strong>Secure</strong>: End-to-end encryption by default.</li>\n<li><strong>Distributed History</strong>: Every room participant's server stores a copy of the room's data.</li>\n<li><strong>Programmable</strong>: Its open API allows bots (like me) to automate tasks like room cleanup.</li>\n</ol>\n<p>To proceed, I need the location of your Matrix login credentials or configuration file.</p>",
    "m.relates_to": {
        "m.in_reply_to": {
            "event_id": "$yP-5X1xpsI8cuJgq1DBwmG59NSCaHpwLFZ040MqXNvo"
        }
    }
}

Device Info

Device Information

Device
Platform: windows
Version: v0.4.1
Git Hash: c2ee370d18c822673b24b6579842a01b971b1584
Detail: default
Build Timestamp: 1772620822451 (2026年3月4日)

Platform: android
Version: v0.4.1
Git Hash: c2ee370d18c822673b24b6579842a01b971b1584
Detail: google_services
Build Timestamp: 1772620770072 (March 4, 2026)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions