File tree 2 files changed +23
-2
lines changed 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ class HtmlParser extends StatelessWidget {
69
69
// scaling is used, but relies on https://github.com/flutter/flutter/pull/59711
70
70
// to wrap everything when larger accessibility fonts are used.
71
71
return StyledText (
72
- textSpan: parsedTree,
72
+ textSpan: parsedTree,
73
73
style: cleanedTree.style,
74
74
textScaleFactor: MediaQuery .of (context).textScaleFactor,
75
75
);
@@ -439,13 +439,15 @@ class HtmlParser extends StatelessWidget {
439
439
/// (2) Replace all newlines with a space
440
440
/// (3) Replace all tabs with a space
441
441
/// (4) Replace any instances of two or more spaces with a single space.
442
+ /// (5) Remove remaining leading and trailing spaces.
442
443
static String _removeUnnecessaryWhitespace (String text) {
443
444
return text
444
445
.replaceAll (RegExp ("\ *(?=\n )" ), "\n " )
445
446
.replaceAll (RegExp ("(?:\n )\ *" ), "\n " )
446
447
.replaceAll ("\n " , " " )
447
448
.replaceAll ("\t " , " " )
448
- .replaceAll (RegExp (" {2,}" ), " " );
449
+ .replaceAll (RegExp (" {2,}" ), " " )
450
+ .trim ();
449
451
}
450
452
451
453
/// [processListCharacters] adds list characters to the front of all list items.
Original file line number Diff line number Diff line change @@ -19,6 +19,25 @@ void main() {
19
19
);
20
20
});
21
21
22
+ testWidgets ("Parser trims whitepaces" , (WidgetTester tester) async {
23
+ await tester.pumpWidget (
24
+ MaterialApp (
25
+ home: Scaffold (
26
+ body: Html (
27
+ data: """
28
+ <div>
29
+ content
30
+ </div>
31
+ """ ,
32
+ ),
33
+ ),
34
+ ),
35
+ );
36
+ expect (find.byType (Html ), findsOneWidget);
37
+ expect (find.text ("content" ), findsOneWidget);
38
+ expect (find.text (" content " ), findsNothing);
39
+ });
40
+
22
41
testNewParser ();
23
42
}
24
43
You can’t perform that action at this time.
0 commit comments