@@ -6,6 +6,8 @@ import 'dart:convert';
66import 'package:flutter/gestures.dart' ;
77import 'package:flutter/material.dart' ;
88import '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' ;
911import 'package:flutter_html/src/utils.dart' ;
1012
1113typedef CustomRenderMatcher = bool Function (RenderContext context);
@@ -15,7 +17,8 @@ CustomRenderMatcher tagMatcher(String tag) => (context) {
1517 };
1618
1719CustomRenderMatcher 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 ) &&
1922 (context.tree.children.isNotEmpty ||
2023 context.tree.element? .localName == "hr" );
2124 };
@@ -108,7 +111,7 @@ class SelectableCustomRender extends CustomRender {
108111 }) : super .inlineSpan (inlineSpan: null );
109112}
110113
111- CustomRender blockElementRender ({Style ? style, List <InlineSpan >? children, required Size containingBlockSize }) =>
114+ CustomRender blockElementRender ({Style ? style, List <InlineSpan >? children}) =>
112115 CustomRender .inlineSpan (inlineSpan: (context, buildChildren) {
113116 if (context.parser.selectable) {
114117 return TextSpan (
@@ -127,36 +130,36 @@ CustomRender blockElementRender({Style? style, List<InlineSpan>? children, requi
127130 );
128131 }
129132 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+ );
148153 });
149154
150155CustomRender listElementRender (
151- {Style ? style, Widget ? child, List <InlineSpan >? children, required Size containingBlockSize }) =>
156+ {Style ? style, Widget ? child, List <InlineSpan >? children}) =>
152157 CustomRender .inlineSpan (
153158 inlineSpan: (context, buildChildren) => WidgetSpan (
154- child: ContainerSpan (
159+ child: CSSBoxWidget (
155160 key: context.key,
156- renderContext: context,
157161 style: style ?? context.tree.style,
158162 shrinkWrap: context.parser.shrinkWrap,
159- containingBlockSize: containingBlockSize,
160163 child: Row (
161164 crossAxisAlignment: CrossAxisAlignment .start,
162165 mainAxisSize: MainAxisSize .min,
@@ -203,9 +206,8 @@ CustomRender listElementRender(
203206 ? 10.0
204207 : 0.0 )
205208 : EdgeInsets .zero,
206- child: StyledText (
207- textSpan: TextSpan (
208- children: _getListElementChildren (
209+ child: CSSBoxWidget .withInlineSpanChildren (
210+ children: _getListElementChildren (
209211 style? .listStylePosition ??
210212 context.tree.style.listStylePosition,
211213 buildChildren)
@@ -225,16 +227,15 @@ CustomRender listElementRender(
225227 height: 0 , width: 0 ))
226228 ]
227229 : []),
228- style: style? .generateTextStyle () ??
229- context.style.generateTextStyle (),
230- ),
231230 style: style ?? context.style,
232- renderContext: context,
233- )))
231+ ),
232+ ),
233+ ),
234234 ],
235235 ),
236236 ),
237- ));
237+ ),
238+ );
238239
239240CustomRender replacedElementRender (
240241 {PlaceholderAlignment ? alignment,
@@ -475,14 +476,9 @@ CustomRender verticalAlignRender(
475476 key: context.key,
476477 offset: Offset (
477478 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 (),
484481 style: context.style,
485- renderContext: context,
486482 ),
487483 ),
488484 ));
@@ -505,10 +501,10 @@ CustomRender fallbackRender({Style? style, List<InlineSpan>? children}) =>
505501 .toList (),
506502 ));
507503
508- Map <CustomRenderMatcher , CustomRender > generateDefaultRenders (Size containingBlockSize ) {
504+ Map <CustomRenderMatcher , CustomRender > generateDefaultRenders () {
509505 return {
510- blockElementMatcher (): blockElementRender (containingBlockSize : containingBlockSize ),
511- listElementMatcher (): listElementRender (containingBlockSize : containingBlockSize ),
506+ blockElementMatcher (): blockElementRender (),
507+ listElementMatcher (): listElementRender (),
512508 textContentElementMatcher (): textContentElementRender (),
513509 dataUriMatcher (): base64ImageRender (),
514510 assetUriMatcher (): assetImageRender (),
0 commit comments