@@ -6,6 +6,8 @@ import 'dart:convert';
6
6
import 'package:flutter/gestures.dart' ;
7
7
import 'package:flutter/material.dart' ;
8
8
import 'package:flutter_html/flutter_html.dart' ;
9
+ import 'package:flutter_html/src/css_box_widget.dart' ;
10
+ import 'package:flutter_html/src/html_elements.dart' ;
9
11
import 'package:flutter_html/src/utils.dart' ;
10
12
11
13
typedef CustomRenderMatcher = bool Function (RenderContext context);
@@ -15,7 +17,8 @@ CustomRenderMatcher tagMatcher(String tag) => (context) {
15
17
};
16
18
17
19
CustomRenderMatcher blockElementMatcher () => (context) {
18
- return context.tree.style.display == Display .BLOCK &&
20
+ return (context.tree.style.display == Display .BLOCK ||
21
+ context.tree.style.display == Display .INLINE_BLOCK ) &&
19
22
(context.tree.children.isNotEmpty ||
20
23
context.tree.element? .localName == "hr" );
21
24
};
@@ -108,7 +111,7 @@ class SelectableCustomRender extends CustomRender {
108
111
}) : super .inlineSpan (inlineSpan: null );
109
112
}
110
113
111
- CustomRender blockElementRender ({Style ? style, List <InlineSpan >? children, required Size containingBlockSize }) =>
114
+ CustomRender blockElementRender ({Style ? style, List <InlineSpan >? children}) =>
112
115
CustomRender .inlineSpan (inlineSpan: (context, buildChildren) {
113
116
if (context.parser.selectable) {
114
117
return TextSpan (
@@ -127,36 +130,36 @@ CustomRender blockElementRender({Style? style, List<InlineSpan>? children, requi
127
130
);
128
131
}
129
132
return WidgetSpan (
130
- child: ContainerSpan (
131
- key: context.key,
132
- renderContext: context,
133
- style: style ?? context.tree.style,
134
- shrinkWrap: context.parser.shrinkWrap,
135
- containingBlockSize: containingBlockSize,
136
- children: children ??
137
- context.tree.children
138
- .expandIndexed ((i, childTree) => [
139
- context.parser.parseTree (context, childTree),
140
- if (i != context.tree.children.length - 1 &&
141
- childTree.style.display == Display .BLOCK &&
142
- childTree.element? .localName != "html" &&
143
- childTree.element? .localName != "body" )
144
- TextSpan (text: "\n " ),
145
- ])
146
- .toList (),
147
- ));
133
+ alignment: PlaceholderAlignment .baseline,
134
+ baseline: TextBaseline .alphabetic,
135
+ child: CSSBoxWidget .withInlineSpanChildren (
136
+ key: context.key,
137
+ style: style ?? context.tree.style,
138
+ shrinkWrap: context.parser.shrinkWrap,
139
+ childIsReplaced: REPLACED_EXTERNAL_ELEMENTS .contains (context.tree.name),
140
+ children: children ??
141
+ context.tree.children
142
+ .expandIndexed ((i, childTree) => [
143
+ context.parser.parseTree (context, childTree),
144
+ //TODO can this newline be added in a different step?
145
+ if (i != context.tree.children.length - 1 &&
146
+ childTree.style.display == Display .BLOCK &&
147
+ childTree.element? .localName != "html" &&
148
+ childTree.element? .localName != "body" )
149
+ TextSpan (text: "\n " ),
150
+ ]).toList (),
151
+ ),
152
+ );
148
153
});
149
154
150
155
CustomRender listElementRender (
151
- {Style ? style, Widget ? child, List <InlineSpan >? children, required Size containingBlockSize }) =>
156
+ {Style ? style, Widget ? child, List <InlineSpan >? children}) =>
152
157
CustomRender .inlineSpan (
153
158
inlineSpan: (context, buildChildren) => WidgetSpan (
154
- child: ContainerSpan (
159
+ child: CSSBoxWidget (
155
160
key: context.key,
156
- renderContext: context,
157
161
style: style ?? context.tree.style,
158
162
shrinkWrap: context.parser.shrinkWrap,
159
- containingBlockSize: containingBlockSize,
160
163
child: Row (
161
164
crossAxisAlignment: CrossAxisAlignment .start,
162
165
mainAxisSize: MainAxisSize .min,
@@ -203,9 +206,8 @@ CustomRender listElementRender(
203
206
? 10.0
204
207
: 0.0 )
205
208
: EdgeInsets .zero,
206
- child: StyledText (
207
- textSpan: TextSpan (
208
- children: _getListElementChildren (
209
+ child: CSSBoxWidget .withInlineSpanChildren (
210
+ children: _getListElementChildren (
209
211
style? .listStylePosition ??
210
212
context.tree.style.listStylePosition,
211
213
buildChildren)
@@ -225,16 +227,15 @@ CustomRender listElementRender(
225
227
height: 0 , width: 0 ))
226
228
]
227
229
: []),
228
- style: style? .generateTextStyle () ??
229
- context.style.generateTextStyle (),
230
- ),
231
230
style: style ?? context.style,
232
- renderContext: context,
233
- )))
231
+ ),
232
+ ),
233
+ ),
234
234
],
235
235
),
236
236
),
237
- ));
237
+ ),
238
+ );
238
239
239
240
CustomRender replacedElementRender (
240
241
{PlaceholderAlignment ? alignment,
@@ -475,14 +476,9 @@ CustomRender verticalAlignRender(
475
476
key: context.key,
476
477
offset: Offset (
477
478
0 , verticalOffset ?? _getVerticalOffset (context.tree)),
478
- child: StyledText (
479
- textSpan: TextSpan (
480
- style: style? .generateTextStyle () ??
481
- context.style.generateTextStyle (),
482
- children: children ?? buildChildren.call (),
483
- ),
479
+ child: CSSBoxWidget .withInlineSpanChildren (
480
+ children: children ?? buildChildren.call (),
484
481
style: context.style,
485
- renderContext: context,
486
482
),
487
483
),
488
484
));
@@ -505,10 +501,10 @@ CustomRender fallbackRender({Style? style, List<InlineSpan>? children}) =>
505
501
.toList (),
506
502
));
507
503
508
- Map <CustomRenderMatcher , CustomRender > generateDefaultRenders (Size containingBlockSize ) {
504
+ Map <CustomRenderMatcher , CustomRender > generateDefaultRenders () {
509
505
return {
510
- blockElementMatcher (): blockElementRender (containingBlockSize : containingBlockSize ),
511
- listElementMatcher (): listElementRender (containingBlockSize : containingBlockSize ),
506
+ blockElementMatcher (): blockElementRender (),
507
+ listElementMatcher (): listElementRender (),
512
508
textContentElementMatcher (): textContentElementRender (),
513
509
dataUriMatcher (): base64ImageRender (),
514
510
assetUriMatcher (): assetImageRender (),
0 commit comments