fix: Trim plaintext after removeMarkdown
This commit is contained in:
parent
7e7e518074
commit
1f93193190
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue