1+ import 'package:flutter_test/flutter_test.dart' ;
2+ import 'package:insporation/src/client.dart' ;
3+ import 'package:insporation/src/markdown_extensions.dart' as mde;
4+ import 'package:markdown/markdown.dart' as md;
5+
6+ String renderMessageMarkdown (String body, {Map <String , Person >? mentionedPeople}) {
7+ return md.markdownToHtml (
8+ body,
9+ blockSyntaxes: [
10+ md.TableSyntax (),
11+ md.FencedCodeBlockSyntax (),
12+ ],
13+ inlineSyntaxes: [
14+ md.InlineHtmlSyntax (),
15+ mde.SuperscriptSyntax (),
16+ mde.SubscriptSyntax (),
17+ md.StrikethroughSyntax (),
18+ md.AutolinkExtensionSyntax (),
19+ mde.TagLinkSyntax (),
20+ mde.MentionLinkSyntax ((diasporaId, inlineName) {
21+ final people = mentionedPeople;
22+ return people != null ? people[diasporaId] : null ;
23+ }),
24+ mde.SingleNewlineBreakSyntax (),
25+ mde.DiasporaAutolinkSyntax (),
26+ ],
27+ );
28+ }
29+
30+ void main () {
31+ test ('single newline in paragraph renders as html break' , () {
32+ final html = renderMessageMarkdown ('hello\n world' );
33+
34+ expect (html, contains ('<br' ));
35+ });
36+
37+ test ('fenced code block newlines are not converted to html breaks' , () {
38+ final html = renderMessageMarkdown ('```\n hello\n world\n ```' );
39+
40+ expect (html, contains ('<pre><code>hello\n world\n </code></pre>' ));
41+ expect (html, isNot (contains ('<code>hello<br' )));
42+ });
43+
44+ test ('hard breaks via trailing spaces keep existing behavior' , () {
45+ final html = renderMessageMarkdown ('hello \n world' );
46+
47+ expect (html, contains ('<p>hello<br />\n world</p>' ));
48+ });
49+
50+ test ('inline code does not get newline break conversion' , () {
51+ final html = renderMessageMarkdown ('`hello\n world`' );
52+
53+ expect (html, contains ('<p><code>hello world</code></p>' ));
54+ expect (html, isNot (contains ('<code>hello<br' )));
55+ });
56+ }
0 commit comments