@@ -6,6 +6,8 @@ import 'package:html/parser.dart' as parser;
6
6
import 'package:html/dom.dart' as dom;
7
7
8
8
typedef CustomRender = Widget Function (dom.Node node, List <Widget > children);
9
+ typedef CustomTextStyle = TextStyle Function (dom.Node node, TextStyle baseStyle);
10
+ typedef CustomEdgeInsets = EdgeInsets Function (dom.Node node);
9
11
typedef OnLinkTap = void Function (String url);
10
12
11
13
const OFFSET_TAGS_FONT_SIZE_FACTOR =
@@ -144,6 +146,8 @@ class HtmlRichTextParser extends StatelessWidget {
144
146
this .onLinkTap,
145
147
this .renderNewlines = false ,
146
148
this .html,
149
+ this .customTextStyle,
150
+ this .customEdgeInsets,
147
151
});
148
152
149
153
final double indentSize = 10.0 ;
@@ -152,6 +156,8 @@ class HtmlRichTextParser extends StatelessWidget {
152
156
final onLinkTap;
153
157
final bool renderNewlines;
154
158
final String html;
159
+ final CustomTextStyle customTextStyle;
160
+ final CustomEdgeInsets customEdgeInsets;
155
161
156
162
// style elements set a default style
157
163
// for all child nodes
@@ -472,6 +478,14 @@ class HtmlRichTextParser extends StatelessWidget {
472
478
nextContext.blockType = 'blockquote' ;
473
479
break ;
474
480
}
481
+
482
+ if (customTextStyle != null ) {
483
+ final TextStyle customStyle = customTextStyle (node, childStyle);
484
+ if (customStyle != null ) {
485
+ childStyle = customStyle;
486
+ }
487
+ }
488
+
475
489
nextContext.childStyle = childStyle;
476
490
}
477
491
@@ -610,6 +624,11 @@ class HtmlRichTextParser extends StatelessWidget {
610
624
parseContext.parentElement = null ;
611
625
TextAlign textAlign = TextAlign .left;
612
626
627
+ EdgeInsets _customEdgeInsets;
628
+ if (customEdgeInsets != null ) {
629
+ _customEdgeInsets = customEdgeInsets (node);
630
+ }
631
+
613
632
switch (node.localName) {
614
633
case "hr" :
615
634
parseContext.rootWidgetList
@@ -715,10 +734,8 @@ class HtmlRichTextParser extends StatelessWidget {
715
734
));
716
735
}
717
736
BlockText blockText = BlockText (
718
- margin: EdgeInsets .only (
719
- top: 8.0 ,
720
- bottom: 8.0 ,
721
- left: parseContext.indentLevel * indentSize),
737
+ margin: _customEdgeInsets ??
738
+ EdgeInsets .only (top: 8.0 , bottom: 8.0 , left: parseContext.indentLevel * indentSize),
722
739
padding: EdgeInsets .all (2.0 ),
723
740
decoration: decoration,
724
741
child: RichText (
0 commit comments