@@ -251,11 +251,84 @@ TableStyleElement parseTableDefinitionElement(
251
251
}
252
252
}
253
253
254
+ class DetailsContentElement extends LayoutElement {
255
+ List <dom.Element > elementList;
256
+
257
+ DetailsContentElement ({
258
+ String name,
259
+ List <StyledElement > children,
260
+ dom.Element node,
261
+ this .elementList,
262
+ }) : super (name: name, node: node, children: children);
263
+
264
+ @override
265
+ Widget toWidget (RenderContext context) {
266
+ List <InlineSpan > childrenList = children? .map ((tree) => context.parser.parseTree (context, tree))? .toList ();
267
+ List <InlineSpan > toRemove = [];
268
+ if (childrenList != null ) {
269
+ for (InlineSpan child in childrenList) {
270
+ if (child is TextSpan && child.text != null && child.text.trim ().isEmpty) {
271
+ toRemove.add (child);
272
+ }
273
+ }
274
+ for (InlineSpan child in toRemove) {
275
+ childrenList.remove (child);
276
+ }
277
+ }
278
+ InlineSpan firstChild = childrenList? .isNotEmpty == true ? childrenList.first : null ;
279
+ return ExpansionTile (
280
+ expandedAlignment: Alignment .centerLeft,
281
+ title: elementList? .isNotEmpty == true && elementList? .first? .localName == "summary" ? StyledText (
282
+ textSpan: TextSpan (
283
+ style: style.generateTextStyle (),
284
+ children: [firstChild] ?? [],
285
+ ),
286
+ style: style,
287
+ ) : Text ("Details" ),
288
+ children: [
289
+ StyledText (
290
+ textSpan: TextSpan (
291
+ style: style.generateTextStyle (),
292
+ children: getChildren (childrenList, context, elementList? .isNotEmpty == true && elementList? .first? .localName == "summary" ? firstChild : null )
293
+ ),
294
+ style: style,
295
+ ),
296
+ ]
297
+ );
298
+ }
299
+
300
+ List <InlineSpan > getChildren (List <InlineSpan > children, RenderContext context, InlineSpan firstChild) {
301
+ if (children == null ) {
302
+ return [];
303
+ } else {
304
+ if (firstChild != null ) children.removeAt (0 );
305
+ return children;
306
+ }
307
+ }
308
+ }
309
+
310
+ class EmptyLayoutElement extends LayoutElement {
311
+ EmptyLayoutElement ({String name = "empty" }) : super (name: name);
312
+
313
+ @override
314
+ Widget toWidget (_) => null ;
315
+ }
316
+
254
317
LayoutElement parseLayoutElement (
255
- dom.Element element,
256
- List <StyledElement > children,
318
+ dom.Element element,
319
+ List <StyledElement > children,
257
320
) {
258
321
switch (element.localName) {
322
+ case "details" :
323
+ if (children? .isEmpty ?? false ) {
324
+ return EmptyLayoutElement ();
325
+ }
326
+ return DetailsContentElement (
327
+ node: element,
328
+ name: element.localName,
329
+ children: children,
330
+ elementList: element.children
331
+ );
259
332
case "table" :
260
333
return TableLayoutElement (
261
334
name: element.localName,
0 commit comments