cinnyapp / cinny

Yet another matrix client
https://cinny.in
GNU Affero General Public License v3.0
1.87k stars 242 forks source link

HTML formatted messages do not strip excessive whitespace as expected #746

Closed williamkray closed 2 years ago

williamkray commented 2 years ago

Describe the bug

HTML has historically stripped excessive whitespace from text, depending instead on things like <p>, <br />, etc to format beyond single spaces between words.

Bots written in white-space specific code like Python often need to use whitespace for formatting so that the code runs properly, and will often depend on the fact that sending a message in matrix as HTML will remove the excess spacing to return nicely formatted message content.

Cinny appears to be including the whitespace in the HTML rendered messages, resulting in disjointed and oddly formatted messages. For example, a stock ticker bot I run includes the following code to format the message:

        prettyMessage = "<br />".join(
                [
                    f"<b>Current data for <a href=\"https://finance.yahoo.com/quote/{tickerUpper}\">\
                            {pruned_json['longName']}</a> ({tickerUpper}):</b>" ,
                    f"",
                    f"<b>Price:</b> <font color=\"{color}\">${str(pruned_json['regularMarketPrice'])}, \
                            {arrow}{openPercentDiff}</font> from market open @ ${str(pruned_json['regularMarketOpen'])}",
                    f"<b>52 Week High:</b> ${str(pruned_json['fiftyTwoWeekHigh'])}",
                    f"<b>52 Week Low:</b> ${str(pruned_json['fiftyTwoWeekLow'])}"
                ]
            )

The message content is broken up across multiple lines to adhere to common readability standards by escaping the newline with a \ and indenting the continuation. In element, this still results in a message formatted as expected: image

But Cinny renders the extra spaces and results in an oddly formatted message: image

Reproduction

  1. use Element-web/desktop to send the following message: /html <p>this is text</p>
  2. the message will render as this is text in element
  3. view the message in cinny, where the message will be rendered as this is text

Expected behavior

Cinny should render the message as this is text

Platform and versions

1. OS: Arch Linux
2. Browser: Firefox 103.0.1
3. Cinny Version: 2.1.2
4. Matrix homeserver: jobmachine.org and mssj.me

Additional context

No response

williamkray commented 2 years ago

hilariously, even my sample code i pasted above stripped out the extra spaces between the words in this is text. so just imagine lots of extra spaces added between all three words.

here's the raw markdown format of what i had entered above: image