Skip to content

Commit 449751c

Browse files
committed
bring back maxLines
1 parent 3aac349 commit 449751c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+17
-1261
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions

example/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Hello <b>Wo</b><i>rl</i>d<br>nyaaa <a href="https://example.org/meow">link<br>br
5151
5252
https://example.org meow <sub>low</sub> <sup> high</sup>
5353
<br>
54+
<span data-mx-spoiler="heya">hmm https://example.org how are you?</span>
55+
<br>
5456
<font color="red">red text</font>
5557
hmm <font color="red"> red</font><font color="green"> green</font>
5658
</p>

lib/text_parser.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,9 @@ class TextParser extends StatelessWidget {
566566
final cleanup = (bool thisNodeBlock, bool lastElement) {
567567
if (currentChildren.isNotEmpty) {
568568
widgets.add(CleanRichText(
569-
_optimizeTextspan(TextSpan(children: currentChildren))));
569+
_optimizeTextspan(TextSpan(children: currentChildren)),
570+
maxLines: maxLines,
571+
));
570572
currentChildren = <InlineSpan>[];
571573
}
572574
// trailing blank nodes and trailing SizedBox'es
@@ -603,6 +605,9 @@ class TextParser extends StatelessWidget {
603605
lastNodeBlock = thisNodeBlock;
604606
}
605607
cleanup(lastNodeBlock, true);
608+
while (maxLines != null && widgets.length > maxLines!) {
609+
widgets.removeLast();
610+
}
606611
if (widgets.length == 1) {
607612
return widgets.first;
608613
}
@@ -618,11 +623,13 @@ class TextParser extends StatelessWidget {
618623
Widget _parseNode(
619624
BuildContext context, ParseContext parseContext, dom.Node node) {
620625
if (node is dom.Text) {
621-
return CleanRichText(_parseTextNode(context, parseContext, node));
626+
return CleanRichText(_parseTextNode(context, parseContext, node),
627+
maxLines: maxLines);
622628
} else if (node is dom.Element) {
623629
final tag = node.localName?.toLowerCase();
624630
if (!SUPPORTED_BLOCK_ELEMENTS.contains(tag)) {
625-
return CleanRichText(_parseInlineNode(context, parseContext, node));
631+
return CleanRichText(_parseInlineNode(context, parseContext, node),
632+
maxLines: maxLines);
626633
}
627634
final nextContext = ParseContext.fromContext(parseContext);
628635
final fontSize = nextContext.textStyle.fontSize ?? 14.0;

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_matrix_html
22
description: A Flutter widget for rendering static matrix html tags as Flutter widgets. (Will render over 70 different html tags!)
3-
version: 1.0.0
3+
version: 1.0.1
44
homepage: https://github.com/Sorunome/flutter_matrix_html
55

66
environment:
@@ -11,7 +11,7 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313
cached_network_image: ^3.0.0
14-
matrix_link_text: ^1.0.1
14+
matrix_link_text: ^1.0.2
1515
flutter_math_fork: ^0.3.0+2
1616
flutter_highlight: ^0.7.0
1717
isolate: ^2.0.3

test/golden_test.dart

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/goldens/a.png

-3.29 KB
Binary file not shown.

test/goldens/abbr.png

-3.3 KB
Binary file not shown.

test/goldens/acronym.png

-3.28 KB
Binary file not shown.

test/goldens/address.png

-3.59 KB
Binary file not shown.

test/goldens/article.png

-3.28 KB
Binary file not shown.

0 commit comments

Comments
 (0)