File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 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 {
6969 // scaling is used, but relies on https://github.com/flutter/flutter/pull/59711
7070 // to wrap everything when larger accessibility fonts are used.
7171 return StyledText (
72- textSpan: parsedTree,
72+ textSpan: parsedTree,
7373 style: cleanedTree.style,
7474 textScaleFactor: MediaQuery .of (context).textScaleFactor,
7575 );
@@ -439,13 +439,15 @@ class HtmlParser extends StatelessWidget {
439439 /// (2) Replace all newlines with a space
440440 /// (3) Replace all tabs with a space
441441 /// (4) Replace any instances of two or more spaces with a single space.
442+ /// (5) Remove remaining leading and trailing spaces.
442443 static String _removeUnnecessaryWhitespace (String text) {
443444 return text
444445 .replaceAll (RegExp ("\ *(?=\n )" ), "\n " )
445446 .replaceAll (RegExp ("(?:\n )\ *" ), "\n " )
446447 .replaceAll ("\n " , " " )
447448 .replaceAll ("\t " , " " )
448- .replaceAll (RegExp (" {2,}" ), " " );
449+ .replaceAll (RegExp (" {2,}" ), " " )
450+ .trim ();
449451 }
450452
451453 /// [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() {
1919 );
2020 });
2121
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+
2241 testNewParser ();
2342}
2443
You can’t perform that action at this time.
0 commit comments