From 2d3bfa64a7aafaa28c4538f3a522a3e32382128a Mon Sep 17 00:00:00 2001 From: Krille Date: Thu, 6 Feb 2025 14:47:18 +0100 Subject: [PATCH 1/2] refactor: Improve linebreak logic for html messages --- lib/src/utils/markdown.dart | 14 +++++++++++++- test/markdown_test.dart | 25 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/src/utils/markdown.dart b/lib/src/utils/markdown.dart index 4b1cec4b..7f1f599f 100644 --- a/lib/src/utils/markdown.dart +++ b/lib/src/utils/markdown.dart @@ -212,7 +212,7 @@ String markdown( bool convertLinebreaks = true, }) { var ret = markdownToHtml( - text, + text.replaceNewlines(), extensionSet: ExtensionSet.commonMark, blockSyntaxes: [ BlockLatexSyntax(), @@ -270,6 +270,18 @@ String markdown( } extension on String { + String replaceNewlines() { + // RegEx for at least 3 following \n + final regExp = RegExp(r'(\n{3,})'); + + return replaceAllMapped(regExp, (match) { + final newLineGroup = match.group(0)!; + return newLineGroup + .replaceAll('\n', '
') + .replaceFirst('

', '\n\n'); + }); + } + String convertLinebreaksToBr( String tagName, { bool exclude = false, diff --git a/test/markdown_test.dart b/test/markdown_test.dart index d685f62d..8b56f012 100644 --- a/test/markdown_test.dart +++ b/test/markdown_test.dart @@ -70,14 +70,29 @@ void main() { 'Snape killed Dumbledoor bold', ); }); - test('multiple paragraphs', () { + test('linebreaks', () { + expect(markdown('Heya!\nBeep'), 'Heya!
Beep'); expect(markdown('Heya!\n\nBeep'), '

Heya!

Beep

'); + expect(markdown('Heya!\n\n\nBeep'), '

Heya!


Beep

'); + expect( + markdown('Heya!\n\n\n\nBeep'), + '

Heya!



Beep

', + ); + expect( + markdown('Heya!\n\n\n\nBeep\n\n'), + '

Heya!



Beep

', + ); + expect( + markdown('\n\nHeya!\n\n\n\nBeep'), + '

Heya!



Beep

', + ); + expect( + markdown('\n\nHeya!\n\n\n\nBeep\n '), + '

Heya!



Beep

', + ); }); test('Other block elements', () { - expect(markdown('# blah\n\nblubb'), '

blah

blubb

'); - }); - test('linebreaks', () { - expect(markdown('foxies\ncute'), 'foxies
cute'); + expect(markdown('# blah\n\nblubb'), '

blah


blubb

'); }); test('lists', () { expect( From e4f41fddeb3a39e61d572f111a446cb6be44e083 Mon Sep 17 00:00:00 2001 From: Krille Date: Mon, 10 Feb 2025 10:00:04 +0100 Subject: [PATCH 2/2] fix: WebRTC videoValue missing --- test/markdown_test.dart | 2 +- test/webrtc_stub.dart | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/markdown_test.dart b/test/markdown_test.dart index 8b56f012..12c7b2fa 100644 --- a/test/markdown_test.dart +++ b/test/markdown_test.dart @@ -92,7 +92,7 @@ void main() { ); }); test('Other block elements', () { - expect(markdown('# blah\n\nblubb'), '

blah


blubb

'); + expect(markdown('# blah\n\nblubb'), '

blah

blubb

'); }); test('lists', () { expect( diff --git a/test/webrtc_stub.dart b/test/webrtc_stub.dart index 76897198..e336cf12 100644 --- a/test/webrtc_stub.dart +++ b/test/webrtc_stub.dart @@ -844,4 +844,8 @@ class MockVideoRenderer implements VideoRenderer { // Mock implementation for disposing VideoRenderer Logs().i('Mock: Disposing VideoRenderer'); } + + @override + // TODO: implement videoValue + RTCVideoValue get videoValue => RTCVideoValue.empty; }