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 // return the html tags free body
if (removeMarkdown == true) { if (removeMarkdown == true) {
final html = markdown(body, convertLinebreaks: false); final html = markdown(body, convertLinebreaks: false);
final document = parse( final document = parse(html);
html, body = document.documentElement?.text.trim() ?? body;
);
body = document.documentElement?.text ?? body;
} }
return body; return body;
} }

View File

@ -1274,10 +1274,10 @@ void main() {
{ {
'content': { 'content': {
'body': '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', 'format': 'org.matrix.custom.html',
'formatted_body': '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', 'msgtype': 'm.text',
}, },
'event_id': '\$143273582443PhrSn:example.org', 'event_id': '\$143273582443PhrSn:example.org',
@ -1294,7 +1294,7 @@ void main() {
MatrixDefaultLocalizations(), MatrixDefaultLocalizations(),
removeMarkdown: true, 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( expect(
await event.calcLocalizedBody( await event.calcLocalizedBody(
@ -1302,7 +1302,7 @@ void main() {
removeMarkdown: true, removeMarkdown: true,
plaintextBody: 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( expect(
await event.calcLocalizedBody( await event.calcLocalizedBody(
@ -1310,7 +1310,7 @@ void main() {
removeMarkdown: true, removeMarkdown: true,
withSenderNamePrefix: 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( expect(
await event.calcLocalizedBody( await event.calcLocalizedBody(
@ -1319,7 +1319,7 @@ void main() {
plaintextBody: true, plaintextBody: true,
withSenderNamePrefix: 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( event = Event.fromJson(