Skip to content

Commit f5c2bdc

Browse files
authored
Added support to skip custom render-er if is null
These changes allow skipping the custom render-er and using back the default render-er in some cases, by returning a null value or not returning any value from the function "customRender".
1 parent 5cea1b4 commit f5c2bdc

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

lib/html_parser.dart

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,31 @@ class HtmlParser extends StatelessWidget {
224224
);
225225

226226
if (customRender?.containsKey(tree.name) ?? false) {
227-
return WidgetSpan(
228-
child: ContainerSpan(
227+
dynamic customRenderForElement = customRender[tree.name].call(
228+
newContext,
229+
ContainerSpan(
229230
newContext: newContext,
230231
style: tree.style,
231232
shrinkWrap: context.parser.shrinkWrap,
232-
child: customRender[tree.name].call(
233-
newContext,
234-
ContainerSpan(
235-
newContext: newContext,
236-
style: tree.style,
237-
shrinkWrap: context.parser.shrinkWrap,
238-
children: tree.children
239-
?.map((tree) => parseTree(newContext, tree))
240-
?.toList() ??
241-
[],
242-
),
243-
tree.attributes,
244-
tree.element,
245-
),
233+
children: tree.children
234+
?.map((tree) => parseTree(newContext, tree))
235+
?.toList() ??
236+
[],
246237
),
238+
tree.attributes,
239+
tree.element,
247240
);
241+
242+
if (customRenderForElement != null) {
243+
return WidgetSpan(
244+
child: ContainerSpan(
245+
newContext: newContext,
246+
style: tree.style,
247+
shrinkWrap: context.parser.shrinkWrap,
248+
child: builder,
249+
),
250+
);
251+
}
248252
}
249253

250254
//Return the correct InlineSpan based on the element type.

0 commit comments

Comments
 (0)