Merge pull request #2022 from famedly/krille/fix-linebreaks-in-html-messages-correctly
refactor: Improve linebreak logic for html messages
This commit is contained in:
commit
2f1e423416
|
|
@ -212,7 +212,7 @@ String markdown(
|
||||||
bool convertLinebreaks = true,
|
bool convertLinebreaks = true,
|
||||||
}) {
|
}) {
|
||||||
var ret = markdownToHtml(
|
var ret = markdownToHtml(
|
||||||
text,
|
text.replaceNewlines(),
|
||||||
extensionSet: ExtensionSet.commonMark,
|
extensionSet: ExtensionSet.commonMark,
|
||||||
blockSyntaxes: [
|
blockSyntaxes: [
|
||||||
BlockLatexSyntax(),
|
BlockLatexSyntax(),
|
||||||
|
|
@ -270,6 +270,18 @@ String markdown(
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on String {
|
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', '<br/>')
|
||||||
|
.replaceFirst('<br/><br/>', '\n\n');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
String convertLinebreaksToBr(
|
String convertLinebreaksToBr(
|
||||||
String tagName, {
|
String tagName, {
|
||||||
bool exclude = false,
|
bool exclude = false,
|
||||||
|
|
|
||||||
|
|
@ -70,15 +70,30 @@ void main() {
|
||||||
'Snape killed <span data-mx-spoiler="">Dumbledoor <strong>bold</strong></span>',
|
'Snape killed <span data-mx-spoiler="">Dumbledoor <strong>bold</strong></span>',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('multiple paragraphs', () {
|
test('linebreaks', () {
|
||||||
|
expect(markdown('Heya!\nBeep'), 'Heya!<br/>Beep');
|
||||||
expect(markdown('Heya!\n\nBeep'), '<p>Heya!</p><p>Beep</p>');
|
expect(markdown('Heya!\n\nBeep'), '<p>Heya!</p><p>Beep</p>');
|
||||||
|
expect(markdown('Heya!\n\n\nBeep'), '<p>Heya!</p><p><br/>Beep</p>');
|
||||||
|
expect(
|
||||||
|
markdown('Heya!\n\n\n\nBeep'),
|
||||||
|
'<p>Heya!</p><p><br/><br/>Beep</p>',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
markdown('Heya!\n\n\n\nBeep\n\n'),
|
||||||
|
'<p>Heya!</p><p><br/><br/>Beep</p>',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
markdown('\n\nHeya!\n\n\n\nBeep'),
|
||||||
|
'<p>Heya!</p><p><br/><br/>Beep</p>',
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
markdown('\n\nHeya!\n\n\n\nBeep\n '),
|
||||||
|
'<p>Heya!</p><p><br/><br/>Beep</p>',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('Other block elements', () {
|
test('Other block elements', () {
|
||||||
expect(markdown('# blah\n\nblubb'), '<h1>blah</h1><p>blubb</p>');
|
expect(markdown('# blah\n\nblubb'), '<h1>blah</h1><p>blubb</p>');
|
||||||
});
|
});
|
||||||
test('linebreaks', () {
|
|
||||||
expect(markdown('foxies\ncute'), 'foxies<br/>cute');
|
|
||||||
});
|
|
||||||
test('lists', () {
|
test('lists', () {
|
||||||
expect(
|
expect(
|
||||||
markdown('So we have:\n- foxies\n- cats\n- dogs'),
|
markdown('So we have:\n- foxies\n- cats\n- dogs'),
|
||||||
|
|
|
||||||
|
|
@ -844,4 +844,8 @@ class MockVideoRenderer implements VideoRenderer {
|
||||||
// Mock implementation for disposing VideoRenderer
|
// Mock implementation for disposing VideoRenderer
|
||||||
Logs().i('Mock: Disposing VideoRenderer');
|
Logs().i('Mock: Disposing VideoRenderer');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
// TODO: implement videoValue
|
||||||
|
RTCVideoValue get videoValue => RTCVideoValue.empty;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue