@@ -6,6 +6,8 @@ import 'package:html/dom.dart' as dom;
6
6
import 'package:html/parser.dart' as parser;
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,11 +146,14 @@ 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
this .onImageError,
148
152
this .linkStyle = const TextStyle (
149
153
decoration: TextDecoration .underline,
150
154
color: Colors .blueAccent,
151
- decorationColor: Colors .blueAccent),
155
+ decorationColor: Colors .blueAccent,
156
+ ),
152
157
});
153
158
154
159
final double indentSize = 10.0 ;
@@ -157,6 +162,8 @@ class HtmlRichTextParser extends StatelessWidget {
157
162
final onLinkTap;
158
163
final bool renderNewlines;
159
164
final String html;
165
+ final CustomTextStyle customTextStyle;
166
+ final CustomEdgeInsets customEdgeInsets;
160
167
final ImageErrorListener onImageError;
161
168
final TextStyle linkStyle;
162
169
@@ -485,6 +492,14 @@ class HtmlRichTextParser extends StatelessWidget {
485
492
//No additional styles
486
493
break ;
487
494
}
495
+
496
+ if (customTextStyle != null ) {
497
+ final TextStyle customStyle = customTextStyle (node, childStyle);
498
+ if (customStyle != null ) {
499
+ childStyle = customStyle;
500
+ }
501
+ }
502
+
488
503
nextContext.childStyle = childStyle;
489
504
}
490
505
@@ -619,6 +634,11 @@ class HtmlRichTextParser extends StatelessWidget {
619
634
parseContext.parentElement = null ;
620
635
TextAlign textAlign = TextAlign .left;
621
636
637
+ EdgeInsets _customEdgeInsets;
638
+ if (customEdgeInsets != null ) {
639
+ _customEdgeInsets = customEdgeInsets (node);
640
+ }
641
+
622
642
switch (node.localName) {
623
643
case "hr" :
624
644
parseContext.rootWidgetList
@@ -738,10 +758,8 @@ class HtmlRichTextParser extends StatelessWidget {
738
758
));
739
759
}
740
760
BlockText blockText = BlockText (
741
- margin: EdgeInsets .only (
742
- top: 8.0 ,
743
- bottom: 8.0 ,
744
- left: parseContext.indentLevel * indentSize),
761
+ margin: _customEdgeInsets ??
762
+ EdgeInsets .only (top: 8.0 , bottom: 8.0 , left: parseContext.indentLevel * indentSize),
745
763
padding: EdgeInsets .all (2.0 ),
746
764
decoration: decoration,
747
765
child: RichText (
0 commit comments