@@ -33,11 +33,7 @@ class LinkTextSpan extends TextSpan {
33
33
final String url;
34
34
35
35
LinkTextSpan (
36
- {TextStyle style,
37
- this .url,
38
- String text,
39
- OnLinkTap onLinkTap,
40
- List <TextSpan > children})
36
+ {TextStyle style, this .url, String text, OnLinkTap onLinkTap, List <TextSpan > children})
41
37
: super (
42
38
style: style,
43
39
text: text,
@@ -81,11 +77,7 @@ class BlockText extends StatelessWidget {
81
77
final Decoration decoration;
82
78
83
79
BlockText (
84
- {@required this .child,
85
- this .padding,
86
- this .margin,
87
- this .leadingChar = '' ,
88
- this .decoration});
80
+ {@required this .child, this .padding, this .margin, this .leadingChar = '' , this .decoration});
89
81
90
82
@override
91
83
Widget build (BuildContext context) {
@@ -279,8 +271,7 @@ class HtmlRichTextParser extends StatelessWidget {
279
271
bool _hasBlockChild (dom.Node node, {bool ignoreSelf = true }) {
280
272
bool retval = false ;
281
273
if (node is dom.Element ) {
282
- if (_supportedBlockElements.contains (node.localName) && ! ignoreSelf)
283
- return true ;
274
+ if (_supportedBlockElements.contains (node.localName) && ! ignoreSelf) return true ;
284
275
node.nodes.forEach ((dom.Node node) {
285
276
if (_hasBlockChild (node, ignoreSelf: false )) retval = true ;
286
277
});
@@ -315,8 +306,7 @@ class HtmlRichTextParser extends StatelessWidget {
315
306
if (w is BlockText ) {
316
307
if (w.child.text == null ) return ;
317
308
if ((w.child.text.text == null || w.child.text.text.isEmpty) &&
318
- (w.child.text.children == null || w.child.text.children.isEmpty))
319
- return ;
309
+ (w.child.text.children == null || w.child.text.children.isEmpty)) return ;
320
310
} else if (w is LinkBlock ) {
321
311
if (w.children.isEmpty) return ;
322
312
} else if (w is LinkTextSpan ) {
@@ -343,8 +333,7 @@ class HtmlRichTextParser extends StatelessWidget {
343
333
// function can add child nodes to the parent if it should
344
334
//
345
335
// each iteration creates a new parseContext as a copy of the previous one if it needs to
346
- void _parseNode (
347
- dom.Node node, ParseContext parseContext, BuildContext buildContext) {
336
+ void _parseNode (dom.Node node, ParseContext parseContext, BuildContext buildContext) {
348
337
// TEXT ONLY NODES
349
338
// a text only node is a child of a tag with no inner html
350
339
if (node is dom.Text ) {
@@ -383,18 +372,15 @@ class HtmlRichTextParser extends StatelessWidget {
383
372
// debugPrint("Plain Text Node: '$finalText'");
384
373
385
374
// create a span by default
386
- TextSpan span = TextSpan (
387
- text: finalText,
388
- children: < TextSpan > [],
389
- style: parseContext.childStyle);
375
+ TextSpan span =
376
+ TextSpan (text: finalText, children: < TextSpan > [], style: parseContext.childStyle);
390
377
391
378
// in this class, a ParentElement must be a BlockText, LinkTextSpan, Row, Column, TextSpan
392
379
393
380
// the parseContext might actually be a block level style element, so we
394
381
// need to honor the indent and styling specified by that block style.
395
382
// e.g. ol, ul, blockquote
396
- bool treatLikeBlock =
397
- ['blockquote' , 'ul' , 'ol' ].indexOf (parseContext.blockType) != - 1 ;
383
+ bool treatLikeBlock = ['blockquote' , 'ul' , 'ol' ].indexOf (parseContext.blockType) != - 1 ;
398
384
399
385
// if there is no parentElement, contain the span in a BlockText
400
386
if (parseContext.parentElement == null ) {
@@ -405,18 +391,15 @@ class HtmlRichTextParser extends StatelessWidget {
405
391
Decoration decoration;
406
392
if (parseContext.blockType == 'blockquote' ) {
407
393
decoration = BoxDecoration (
408
- border:
409
- Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
394
+ border: Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
410
395
);
411
396
parseContext.childStyle = parseContext.childStyle.merge (TextStyle (
412
397
fontStyle: FontStyle .italic,
413
398
));
414
399
}
415
400
BlockText blockText = BlockText (
416
- margin: EdgeInsets .only (
417
- top: 8.0 ,
418
- bottom: 8.0 ,
419
- left: parseContext.indentLevel * indentSize),
401
+ margin:
402
+ EdgeInsets .only (top: 8.0 , bottom: 8.0 , left: parseContext.indentLevel * indentSize),
420
403
padding: EdgeInsets .all (2.0 ),
421
404
decoration: decoration,
422
405
child: RichText (
@@ -426,8 +409,7 @@ class HtmlRichTextParser extends StatelessWidget {
426
409
);
427
410
parseContext.rootWidgetList.add (blockText);
428
411
} else {
429
- parseContext.rootWidgetList
430
- .add (BlockText (child: RichText (text: span)));
412
+ parseContext.rootWidgetList.add (BlockText (child: RichText (text: span)));
431
413
}
432
414
433
415
// this allows future items to be added as children of this item
@@ -437,8 +419,7 @@ class HtmlRichTextParser extends StatelessWidget {
437
419
} else if (parseContext.parentElement is LinkTextSpan ) {
438
420
// add this node to the parent as another LinkTextSpan
439
421
parseContext.parentElement.children.add (LinkTextSpan (
440
- style:
441
- parseContext.parentElement.style.merge (parseContext.childStyle),
422
+ style: parseContext.parentElement.style.merge (parseContext.childStyle),
442
423
url: parseContext.parentElement.url,
443
424
text: finalText,
444
425
onLinkTap: onLinkTap,
@@ -471,16 +452,14 @@ class HtmlRichTextParser extends StatelessWidget {
471
452
//"b","i","em","strong","code","u","small","abbr","acronym"
472
453
case "b" :
473
454
case "strong" :
474
- childStyle =
475
- childStyle.merge (TextStyle (fontWeight: FontWeight .bold));
455
+ childStyle = childStyle.merge (TextStyle (fontWeight: FontWeight .bold));
476
456
break ;
477
457
case "i" :
478
458
case "address" :
479
459
case "cite" :
480
460
case "var" :
481
461
case "em" :
482
- childStyle =
483
- childStyle.merge (TextStyle (fontStyle: FontStyle .italic));
462
+ childStyle = childStyle.merge (TextStyle (fontStyle: FontStyle .italic));
484
463
break ;
485
464
case "kbd" :
486
465
case "samp" :
@@ -490,8 +469,7 @@ class HtmlRichTextParser extends StatelessWidget {
490
469
break ;
491
470
case "ins" :
492
471
case "u" :
493
- childStyle = childStyle
494
- .merge (TextStyle (decoration: TextDecoration .underline));
472
+ childStyle = childStyle.merge (TextStyle (decoration: TextDecoration .underline));
495
473
break ;
496
474
case "abbr" :
497
475
case "acronym" :
@@ -507,14 +485,13 @@ class HtmlRichTextParser extends StatelessWidget {
507
485
childStyle = childStyle.merge (TextStyle (fontSize: 10.0 ));
508
486
break ;
509
487
case "mark" :
510
- childStyle = childStyle. merge (
511
- TextStyle (backgroundColor: Colors .yellow, color: Colors .black));
488
+ childStyle =
489
+ childStyle. merge ( TextStyle (backgroundColor: Colors .yellow, color: Colors .black));
512
490
break ;
513
491
case "del" :
514
492
case "s" :
515
493
case "strike" :
516
- childStyle = childStyle
517
- .merge (TextStyle (decoration: TextDecoration .lineThrough));
494
+ childStyle = childStyle.merge (TextStyle (decoration: TextDecoration .lineThrough));
518
495
break ;
519
496
case "ol" :
520
497
nextContext.indentLevel += 1 ;
@@ -567,8 +544,7 @@ class HtmlRichTextParser extends StatelessWidget {
567
544
if (_hasBlockChild (node)) {
568
545
LinkBlock linkContainer = LinkBlock (
569
546
url: url,
570
- margin: EdgeInsets .only (
571
- left: parseContext.indentLevel * indentSize),
547
+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize),
572
548
onLinkTap: onLinkTap,
573
549
children: < Widget > [],
574
550
);
@@ -587,8 +563,7 @@ class HtmlRichTextParser extends StatelessWidget {
587
563
} else {
588
564
// start a new block element for this link and its text
589
565
BlockText blockElement = BlockText (
590
- margin: EdgeInsets .only (
591
- left: parseContext.indentLevel * indentSize, top: 10.0 ),
566
+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize, top: 10.0 ),
592
567
child: RichText (text: span),
593
568
);
594
569
parseContext.rootWidgetList.add (blockElement);
@@ -600,10 +575,8 @@ class HtmlRichTextParser extends StatelessWidget {
600
575
break ;
601
576
602
577
case "br" :
603
- if (parseContext.parentElement != null &&
604
- parseContext.parentElement is TextSpan ) {
605
- parseContext.parentElement.children
606
- .add (TextSpan (text: '\n ' , children: []));
578
+ if (parseContext.parentElement != null && parseContext.parentElement is TextSpan ) {
579
+ parseContext.parentElement.children.add (TextSpan (text: '\n ' , children: []));
607
580
}
608
581
break ;
609
582
@@ -615,8 +588,7 @@ class HtmlRichTextParser extends StatelessWidget {
615
588
children: < Widget > [],
616
589
);
617
590
nextContext.rootWidgetList.add (Container (
618
- margin: EdgeInsets .symmetric (vertical: 12.0 ),
619
- child: nextContext.parentElement));
591
+ margin: EdgeInsets .symmetric (vertical: 12.0 ), child: nextContext.parentElement));
620
592
break ;
621
593
622
594
// we don't handle tbody, thead, or tfoot elements separately for now
@@ -632,11 +604,8 @@ class HtmlRichTextParser extends StatelessWidget {
632
604
colspan = int .tryParse (node.attributes['colspan' ]);
633
605
}
634
606
nextContext.childStyle = nextContext.childStyle.merge (TextStyle (
635
- fontWeight: (node.localName == 'th' )
636
- ? FontWeight .bold
637
- : FontWeight .normal));
638
- RichText text =
639
- RichText (text: TextSpan (text: '' , children: < TextSpan > []));
607
+ fontWeight: (node.localName == 'th' ) ? FontWeight .bold : FontWeight .normal));
608
+ RichText text = RichText (text: TextSpan (text: '' , children: < TextSpan > []));
640
609
Expanded cell = Expanded (
641
610
flex: colspan,
642
611
child: Container (padding: EdgeInsets .all (1.0 ), child: text),
@@ -675,14 +644,11 @@ class HtmlRichTextParser extends StatelessWidget {
675
644
nextContext.parentElement = text.text;
676
645
break ;
677
646
case "q" :
678
- if (parseContext.parentElement != null &&
679
- parseContext.parentElement is TextSpan ) {
680
- parseContext.parentElement.children
681
- .add (TextSpan (text: '"' , children: []));
647
+ if (parseContext.parentElement != null && parseContext.parentElement is TextSpan ) {
648
+ parseContext.parentElement.children.add (TextSpan (text: '"' , children: []));
682
649
TextSpan content = TextSpan (text: '' , children: []);
683
650
parseContext.parentElement.children.add (content);
684
- parseContext.parentElement.children
685
- .add (TextSpan (text: '"' , children: []));
651
+ parseContext.parentElement.children.add (TextSpan (text: '"' , children: []));
686
652
nextContext.parentElement = content;
687
653
}
688
654
break ;
@@ -703,8 +669,7 @@ class HtmlRichTextParser extends StatelessWidget {
703
669
704
670
switch (node.localName) {
705
671
case "hr" :
706
- parseContext.rootWidgetList
707
- .add (Divider (height: 1.0 , color: Colors .black38));
672
+ parseContext.rootWidgetList.add (Divider (height: 1.0 , color: Colors .black38));
708
673
break ;
709
674
case "img" :
710
675
if (showImages) {
@@ -722,8 +687,7 @@ class HtmlRichTextParser extends StatelessWidget {
722
687
);
723
688
parseContext.rootWidgetList.add (GestureDetector (
724
689
child: Image .memory (
725
- base64.decode (
726
- node.attributes['src' ].split ("base64," )[1 ].trim ()),
690
+ base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ()),
727
691
width: imageProperties? .width ??
728
692
((node.attributes['width' ] != null )
729
693
? double .parse (node.attributes['width' ])
@@ -806,8 +770,7 @@ class HtmlRichTextParser extends StatelessWidget {
806
770
leadingChar = parseContext.listCount.toString () + '.' ;
807
771
}
808
772
BlockText blockText = BlockText (
809
- margin: EdgeInsets .only (
810
- left: parseContext.indentLevel * indentSize, top: 3.0 ),
773
+ margin: EdgeInsets .only (left: parseContext.indentLevel * indentSize, top: 3.0 ),
811
774
child: RichText (
812
775
text: TextSpan (
813
776
text: '' ,
@@ -868,8 +831,7 @@ class HtmlRichTextParser extends StatelessWidget {
868
831
Decoration decoration;
869
832
if (parseContext.blockType == 'blockquote' ) {
870
833
decoration = BoxDecoration (
871
- border:
872
- Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
834
+ border: Border (left: BorderSide (color: Colors .black38, width: 2.0 )),
873
835
);
874
836
nextContext.childStyle = nextContext.childStyle.merge (TextStyle (
875
837
fontStyle: FontStyle .italic,
@@ -879,9 +841,7 @@ class HtmlRichTextParser extends StatelessWidget {
879
841
margin: node.localName != 'body'
880
842
? _customEdgeInsets ??
881
843
EdgeInsets .only (
882
- top: 8.0 ,
883
- bottom: 8.0 ,
884
- left: parseContext.indentLevel * indentSize)
844
+ top: 8.0 , bottom: 8.0 , left: parseContext.indentLevel * indentSize)
885
845
: EdgeInsets .zero,
886
846
padding: EdgeInsets .all (2.0 ),
887
847
decoration: decoration,
@@ -1070,8 +1030,7 @@ class HtmlOldParser extends StatelessWidget {
1070
1030
1071
1031
Widget _parseNode (dom.Node node) {
1072
1032
if (customRender != null ) {
1073
- final Widget customWidget =
1074
- customRender (node, _parseNodeList (node.nodes));
1033
+ final Widget customWidget = customRender (node, _parseNodeList (node.nodes));
1075
1034
if (customWidget != null ) {
1076
1035
return customWidget;
1077
1036
}
@@ -1161,9 +1120,8 @@ class HtmlOldParser extends StatelessWidget {
1161
1120
child: Wrap (
1162
1121
children: _parseNodeList (node.nodes),
1163
1122
),
1164
- textDirection: node.attributes["dir" ] == "rtl"
1165
- ? TextDirection .rtl
1166
- : TextDirection .ltr,
1123
+ textDirection:
1124
+ node.attributes["dir" ] == "rtl" ? TextDirection .rtl : TextDirection .ltr,
1167
1125
);
1168
1126
}
1169
1127
//Direction attribute is required, just render the text normally now.
@@ -1181,8 +1139,7 @@ class HtmlOldParser extends StatelessWidget {
1181
1139
);
1182
1140
case "blockquote" :
1183
1141
return Padding (
1184
- padding:
1185
- EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1142
+ padding: EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1186
1143
child: Container (
1187
1144
width: width,
1188
1145
child: Wrap (
@@ -1305,8 +1262,7 @@ class HtmlOldParser extends StatelessWidget {
1305
1262
);
1306
1263
case "figure" :
1307
1264
return Padding (
1308
- padding:
1309
- EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1265
+ padding: EdgeInsets .fromLTRB (40.0 , blockSpacing, 40.0 , blockSpacing),
1310
1266
child: Column (
1311
1267
children: _parseNodeList (node.nodes),
1312
1268
crossAxisAlignment: CrossAxisAlignment .center,
@@ -1437,13 +1393,12 @@ class HtmlOldParser extends StatelessWidget {
1437
1393
if (node.attributes['src' ].startsWith ("data:image" ) &&
1438
1394
node.attributes['src' ].contains ("base64," )) {
1439
1395
precacheImage (
1440
- MemoryImage (base64.decode (
1441
- node.attributes['src' ].split ("base64," )[1 ].trim ())),
1396
+ MemoryImage (base64.decode (node.attributes['src' ].split ("base64," )[1 ].trim ())),
1442
1397
context,
1443
1398
onError: onImageError,
1444
1399
);
1445
- return Image .memory (base64. decode (
1446
- node.attributes['src' ].split ("base64," )[1 ].trim ()));
1400
+ return Image .memory (
1401
+ base64. decode ( node.attributes['src' ].split ("base64," )[1 ].trim ()));
1447
1402
}
1448
1403
precacheImage (
1449
1404
NetworkImage (node.attributes['src' ]),
@@ -1455,8 +1410,7 @@ class HtmlOldParser extends StatelessWidget {
1455
1410
//Temp fix for https://github.com/flutter/flutter/issues/736
1456
1411
if (node.attributes['alt' ].endsWith (" " )) {
1457
1412
return Container (
1458
- padding: EdgeInsets .only (right: 2.0 ),
1459
- child: Text (node.attributes['alt' ]));
1413
+ padding: EdgeInsets .only (right: 2.0 ), child: Text (node.attributes['alt' ]));
1460
1414
} else {
1461
1415
return Text (node.attributes['alt' ]);
1462
1416
}
@@ -1678,9 +1632,8 @@ class HtmlOldParser extends StatelessWidget {
1678
1632
painter = new TextPainter (
1679
1633
text: new TextSpan (
1680
1634
text: node.text,
1681
- style: parentStyle.merge (TextStyle (
1682
- fontSize:
1683
- parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR )),
1635
+ style: parentStyle.merge (
1636
+ TextStyle (fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR )),
1684
1637
),
1685
1638
textDirection: TextDirection .ltr);
1686
1639
painter.layout ();
@@ -1711,8 +1664,7 @@ class HtmlOldParser extends StatelessWidget {
1711
1664
top: node.localName == "sub" ? null : 0 ,
1712
1665
),
1713
1666
style: TextStyle (
1714
- fontSize: parentStyle.fontSize *
1715
- OFFSET_TAGS_FONT_SIZE_FACTOR ),
1667
+ fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR ),
1716
1668
)
1717
1669
],
1718
1670
)
@@ -1827,8 +1779,7 @@ class HtmlOldParser extends StatelessWidget {
1827
1779
String finalText = trimStringHtml (node.text);
1828
1780
//Temp fix for https://github.com/flutter/flutter/issues/736
1829
1781
if (finalText.endsWith (" " )) {
1830
- return Container (
1831
- padding: EdgeInsets .only (right: 2.0 ), child: Text (finalText));
1782
+ return Container (padding: EdgeInsets .only (right: 2.0 ), child: Text (finalText));
1832
1783
} else {
1833
1784
return Text (finalText);
1834
1785
}
0 commit comments