Merge pull request #2063 from famedly/krille/trim-plain-test-output

fix: Trim plaintext after removeMarkdown
This commit is contained in:
Karthikeyan S 2025-03-29 16:18:42 +05:30 committed by GitHub
commit dc34202ccf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 10 deletions

View File

@ -955,10 +955,8 @@ class Event extends MatrixEvent {
// return the html tags free body
if (removeMarkdown == true) {
final html = markdown(body, convertLinebreaks: false);
final document = parse(
html,
);
body = document.documentElement?.text ?? body;
final document = parse(html);
body = document.documentElement?.text.trim() ?? body;
}
return body;
}

View File

@ -1274,10 +1274,10 @@ void main() {
{
'content': {
'body':
'# Title\nsome text and [link](https://example.com)\nokay and this is **important**',
'> Quote\n# Title\nsome text and [link](https://example.com)\nokay and this is **important**',
'format': 'org.matrix.custom.html',
'formatted_body':
'<h1>Title</h1>\n<p>some text and <a href="https://example.com">link</a><br>okay and this is <strong>important</strong></p>\n',
'<blockquote><p>Quote</p></blockquote><h1>Title</h1>\n<p>some text and <a href="https://example.com">link</a><br>okay and this is <strong>important</strong></p>\n',
'msgtype': 'm.text',
},
'event_id': '\$143273582443PhrSn:example.org',
@ -1294,7 +1294,7 @@ void main() {
MatrixDefaultLocalizations(),
removeMarkdown: true,
),
'Title\nsome text and link\nokay and this is important',
'Quote\n\nTitle\nsome text and link\nokay and this is important',
);
expect(
await event.calcLocalizedBody(
@ -1302,7 +1302,7 @@ void main() {
removeMarkdown: true,
plaintextBody: true,
),
'Title\nsome text and 🔗link\nokay and this is important',
'Quote\n\nTitle\nsome text and 🔗link\nokay and this is important',
);
expect(
await event.calcLocalizedBody(
@ -1310,7 +1310,7 @@ void main() {
removeMarkdown: true,
withSenderNamePrefix: true,
),
'Example: Title\nsome text and link\nokay and this is important',
'Example: Quote\n\nTitle\nsome text and link\nokay and this is important',
);
expect(
await event.calcLocalizedBody(
@ -1319,7 +1319,7 @@ void main() {
plaintextBody: true,
withSenderNamePrefix: true,
),
'Example: Title\nsome text and 🔗link\nokay and this is important',
'Example: Quote\n\nTitle\nsome text and 🔗link\nokay and this is important',
);
event = Event.fromJson(