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..12c7b2fa 100644 --- a/test/markdown_test.dart +++ b/test/markdown_test.dart @@ -70,15 +70,30 @@ 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'); - }); test('lists', () { expect( markdown('So we have:\n- foxies\n- cats\n- dogs'), 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; }