@@ -175,6 +175,7 @@ class HtmlRichTextParser extends StatelessWidget {
175
175
"br" ,
176
176
"table" ,
177
177
"tbody" ,
178
+ "caption" ,
178
179
"td" ,
179
180
"tfoot" ,
180
181
"th" ,
@@ -401,7 +402,7 @@ class HtmlRichTextParser extends StatelessWidget {
401
402
// OTHER ELEMENT NODES
402
403
else if (node is dom.Element ) {
403
404
assert (() {
404
- // debugPrint("Found ${node.localName}");
405
+ debugPrint ("Found ${node .localName }" );
405
406
// debugPrint(node.outerHtml);
406
407
return true ;
407
408
}());
@@ -532,26 +533,15 @@ class HtmlRichTextParser extends StatelessWidget {
532
533
crossAxisAlignment: CrossAxisAlignment .start,
533
534
children: < Widget > [],
534
535
);
535
- nextContext.rootWidgetList.add (nextContext.parentElement);
536
+ nextContext.rootWidgetList.add (Container (
537
+ margin: EdgeInsets .symmetric (vertical: 12.0 ),
538
+ child: nextContext.parentElement));
536
539
break ;
537
540
538
- // we don't handle tbody or thead elements separately for now
541
+ // we don't handle tbody, thead, or tfoot elements separately for now
539
542
case "tbody" :
540
543
case "thead" :
541
- break ;
542
-
543
- // caption elements throw us off
544
- case "caption" :
545
- RichText text =
546
- RichText (text: TextSpan (text: '' , children: < TextSpan > []));
547
- Row row = Row (
548
- crossAxisAlignment: CrossAxisAlignment .center,
549
- children: < Widget > [
550
- text,
551
- ],
552
- );
553
- nextContext.parentElement.children.add (row);
554
- nextContext.parentElement = text.text;
544
+ case "tfoot" :
555
545
break ;
556
546
557
547
case "td" :
@@ -560,11 +550,15 @@ class HtmlRichTextParser extends StatelessWidget {
560
550
if (node.attributes['colspan' ] != null ) {
561
551
colspan = int .tryParse (node.attributes['colspan' ]);
562
552
}
553
+ nextContext.childStyle = nextContext.childStyle.merge (TextStyle (
554
+ fontWeight: (node.localName == 'th' )
555
+ ? FontWeight .bold
556
+ : FontWeight .normal));
563
557
RichText text =
564
558
RichText (text: TextSpan (text: '' , children: < TextSpan > []));
565
559
Expanded cell = Expanded (
566
560
flex: colspan,
567
- child: text,
561
+ child: Container (padding : EdgeInsets . all ( 1.0 ), child : text) ,
568
562
);
569
563
nextContext.parentElement.children.add (cell);
570
564
nextContext.parentElement = text.text;
@@ -578,6 +572,27 @@ class HtmlRichTextParser extends StatelessWidget {
578
572
nextContext.parentElement.children.add (row);
579
573
nextContext.parentElement = row;
580
574
break ;
575
+
576
+ // treat captions like a row with one expanded cell
577
+ case "caption" :
578
+ // create the row
579
+ Row row = Row (
580
+ crossAxisAlignment: CrossAxisAlignment .center,
581
+ children: < Widget > [],
582
+ );
583
+
584
+ // create an expanded cell
585
+ RichText text = RichText (
586
+ textAlign: TextAlign .center,
587
+ textScaleFactor: 1.2 ,
588
+ text: TextSpan (text: '' , children: < TextSpan > []));
589
+ Expanded cell = Expanded (
590
+ child: Container (padding: EdgeInsets .all (2.0 ), child: text),
591
+ );
592
+ row.children.add (cell);
593
+ nextContext.parentElement.children.add (row);
594
+ nextContext.parentElement = text.text;
595
+ break ;
581
596
}
582
597
}
583
598
0 commit comments