diff --git a/lib/html_parser.dart b/lib/html_parser.dart index a34d6571d3..882d60e5ea 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -224,27 +224,31 @@ class HtmlParser extends StatelessWidget { ); if (customRender?.containsKey(tree.name) ?? false) { - return WidgetSpan( - child: ContainerSpan( + dynamic customRenderForElement = customRender[tree.name].call( + newContext, + ContainerSpan( newContext: newContext, style: tree.style, shrinkWrap: context.parser.shrinkWrap, - child: customRender[tree.name].call( - newContext, - ContainerSpan( - newContext: newContext, - style: tree.style, - shrinkWrap: context.parser.shrinkWrap, - children: tree.children - ?.map((tree) => parseTree(newContext, tree)) - ?.toList() ?? - [], - ), - tree.attributes, - tree.element, - ), + children: tree.children + ?.map((tree) => parseTree(newContext, tree)) + ?.toList() ?? + [], ), + tree.attributes, + tree.element, ); + + if (customRenderForElement != null) { + return WidgetSpan( + child: ContainerSpan( + newContext: newContext, + style: tree.style, + shrinkWrap: context.parser.shrinkWrap, + child: customRenderForElement, + ), + ); + } } //Return the correct InlineSpan based on the element type.