@@ -78,15 +78,19 @@ class HtmlParser extends StatelessWidget {
78
78
79
79
/// [lexDomTree] converts a DOM document to a simplified tree of [StyledElement] s.
80
80
static StyledElement lexDomTree (
81
- dom.Document html, List <String > customRenderTags, List <String > blacklistedElements) {
81
+ dom.Document html,
82
+ List <String > customRenderTags,
83
+ List <String > blacklistedElements,
84
+ ) {
82
85
StyledElement tree = StyledElement (
83
86
name: "[Tree Root]" ,
84
87
children: new List <StyledElement >(),
85
88
node: html.documentElement,
86
89
);
87
90
88
91
html.nodes.forEach ((node) {
89
- tree.children.add (_recursiveLexer (node, customRenderTags, blacklistedElements));
92
+ tree.children
93
+ .add (_recursiveLexer (node, customRenderTags, blacklistedElements));
90
94
});
91
95
92
96
return tree;
@@ -97,11 +101,15 @@ class HtmlParser extends StatelessWidget {
97
101
/// It runs the parse functions of every type of
98
102
/// element and returns a [StyledElement] tree representing the element.
99
103
static StyledElement _recursiveLexer (
100
- dom.Node node, List <String > customRenderTags, List <String > blacklistedElements) {
104
+ dom.Node node,
105
+ List <String > customRenderTags,
106
+ List <String > blacklistedElements,
107
+ ) {
101
108
List <StyledElement > children = List <StyledElement >();
102
109
103
110
node.nodes.forEach ((childNode) {
104
- children.add (_recursiveLexer (childNode, customRenderTags, blacklistedElements));
111
+ children.add (
112
+ _recursiveLexer (childNode, customRenderTags, blacklistedElements));
105
113
});
106
114
107
115
//TODO(Sub6Resources): There's probably a more efficient way to look this up.
@@ -226,7 +234,10 @@ class HtmlParser extends StatelessWidget {
226
234
newContext: newContext,
227
235
style: tree.style,
228
236
shrinkWrap: context.parser.shrinkWrap,
229
- children: tree.children? .map ((tree) => parseTree (newContext, tree))? .toList () ?? [],
237
+ children: tree.children
238
+ ? .map ((tree) => parseTree (newContext, tree))
239
+ ? .toList () ??
240
+ [],
230
241
),
231
242
tree.attributes,
232
243
),
@@ -241,7 +252,10 @@ class HtmlParser extends StatelessWidget {
241
252
newContext: newContext,
242
253
style: tree.style,
243
254
shrinkWrap: context.parser.shrinkWrap,
244
- children: tree.children? .map ((tree) => parseTree (newContext, tree))? .toList () ?? [],
255
+ children: tree.children
256
+ ? .map ((tree) => parseTree (newContext, tree))
257
+ ? .toList () ??
258
+ [],
245
259
),
246
260
);
247
261
} else if (tree.style? .display == Display .LIST_ITEM ) {
@@ -256,14 +270,18 @@ class HtmlParser extends StatelessWidget {
256
270
width: 30 , //TODO derive this from list padding.
257
271
start: 0 ,
258
272
child: Text ('${newContext .style .markerContent }\t ' ,
259
- textAlign: TextAlign .right, style: newContext.style.generateTextStyle ()),
273
+ textAlign: TextAlign .right,
274
+ style: newContext.style.generateTextStyle ()),
260
275
),
261
276
Padding (
262
- padding: EdgeInsets .only (left: 30 ), //TODO derive this from list padding.
277
+ padding: EdgeInsets .only (
278
+ left: 30 ), //TODO derive this from list padding.
263
279
child: RichText (
264
280
text: TextSpan (
265
- children:
266
- tree.children? .map ((tree) => parseTree (newContext, tree))? .toList () ?? [],
281
+ children: tree.children
282
+ ? .map ((tree) => parseTree (newContext, tree))
283
+ ? .toList () ??
284
+ [],
267
285
style: newContext.style.generateTextStyle (),
268
286
),
269
287
),
@@ -286,17 +304,21 @@ class HtmlParser extends StatelessWidget {
286
304
return WidgetSpan (
287
305
child: RawGestureDetector (
288
306
gestures: {
289
- MultipleTapGestureRecognizer : GestureRecognizerFactoryWithHandlers <MultipleTapGestureRecognizer >(
290
- () => MultipleTapGestureRecognizer (),
291
- (instance) {
292
- instance..onTap = () => onLinkTap? .call (tree.href);
293
- },
307
+ MultipleTapGestureRecognizer : GestureRecognizerFactoryWithHandlers <
308
+ MultipleTapGestureRecognizer >(
309
+ () => MultipleTapGestureRecognizer (),
310
+ (instance) {
311
+ instance..onTap = () => onLinkTap? .call (tree.href);
312
+ },
294
313
),
295
314
},
296
315
child: RichText (
297
316
text: TextSpan (
298
317
style: newContext.style.generateTextStyle (),
299
- children: tree.children.map ((tree) => parseTree (newContext, tree)).toList () ?? [],
318
+ children: tree.children
319
+ .map ((tree) => parseTree (newContext, tree))
320
+ .toList () ??
321
+ [],
300
322
),
301
323
),
302
324
),
@@ -325,7 +347,10 @@ class HtmlParser extends StatelessWidget {
325
347
child: RichText (
326
348
text: TextSpan (
327
349
style: newContext.style.generateTextStyle (),
328
- children: tree.children.map ((tree) => parseTree (newContext, tree)).toList () ?? [],
350
+ children: tree.children
351
+ .map ((tree) => parseTree (newContext, tree))
352
+ .toList () ??
353
+ [],
329
354
),
330
355
),
331
356
),
@@ -334,7 +359,8 @@ class HtmlParser extends StatelessWidget {
334
359
///[tree] is an inline element.
335
360
return TextSpan (
336
361
style: newContext.style.generateTextStyle (),
337
- children: tree.children.map ((tree) => parseTree (newContext, tree)).toList (),
362
+ children:
363
+ tree.children.map ((tree) => parseTree (newContext, tree)).toList (),
338
364
);
339
365
}
340
366
}
@@ -367,7 +393,10 @@ class HtmlParser extends StatelessWidget {
367
393
/// [_processInlineWhitespaceRecursive] analyzes the whitespace between and among different
368
394
/// inline elements, and replaces any instance of two or more spaces with a single space, according
369
395
/// to the w3's HTML whitespace processing specification linked to above.
370
- static StyledElement _processInlineWhitespaceRecursive (StyledElement tree, Context <bool > wpc) {
396
+ static StyledElement _processInlineWhitespaceRecursive (
397
+ StyledElement tree,
398
+ Context <bool > wpc,
399
+ ) {
371
400
if (tree.style.display == Display .BLOCK ) {
372
401
wpc.data = false ;
373
402
}
@@ -500,7 +529,8 @@ class HtmlParser extends StatelessWidget {
500
529
if (tree.children.first.style.margin == null ) {
501
530
tree.children.first.style.margin = EdgeInsets .zero;
502
531
} else {
503
- tree.children.first.style.margin = tree.children.first.style.margin.copyWith (top: 0 );
532
+ tree.children.first.style.margin =
533
+ tree.children.first.style.margin.copyWith (top: 0 );
504
534
}
505
535
}
506
536
@@ -515,33 +545,38 @@ class HtmlParser extends StatelessWidget {
515
545
if (tree.style.margin == null ) {
516
546
tree.style.margin = EdgeInsets .only (bottom: newOuterMarginBottom);
517
547
} else {
518
- tree.style.margin = tree.style.margin.copyWith (bottom: newOuterMarginBottom);
548
+ tree.style.margin =
549
+ tree.style.margin.copyWith (bottom: newOuterMarginBottom);
519
550
}
520
551
521
552
// And remove the child's margin
522
553
if (tree.children.last.style.margin == null ) {
523
554
tree.children.last.style.margin = EdgeInsets .zero;
524
555
} else {
525
- tree.children.last.style.margin = tree.children.last.style.margin.copyWith (bottom: 0 );
556
+ tree.children.last.style.margin =
557
+ tree.children.last.style.margin.copyWith (bottom: 0 );
526
558
}
527
559
}
528
560
529
561
// Handle case (2) from above.
530
562
if (tree.children.length > 1 ) {
531
563
for (int i = 1 ; i < tree.children.length; i++ ) {
532
- final previousSiblingBottom = tree.children[i - 1 ].style.margin? .bottom ?? 0 ;
564
+ final previousSiblingBottom =
565
+ tree.children[i - 1 ].style.margin? .bottom ?? 0 ;
533
566
final thisTop = tree.children[i].style.margin? .top ?? 0 ;
534
567
final newInternalMargin = max (previousSiblingBottom, thisTop) / 2 ;
535
568
536
569
if (tree.children[i - 1 ].style.margin == null ) {
537
- tree.children[i - 1 ].style.margin = EdgeInsets .only (bottom: newInternalMargin);
538
- } else {
539
570
tree.children[i - 1 ].style.margin =
540
- tree.children[i - 1 ].style.margin.copyWith (bottom: newInternalMargin);
571
+ EdgeInsets .only (bottom: newInternalMargin);
572
+ } else {
573
+ tree.children[i - 1 ].style.margin = tree.children[i - 1 ].style.margin
574
+ .copyWith (bottom: newInternalMargin);
541
575
}
542
576
543
577
if (tree.children[i].style.margin == null ) {
544
- tree.children[i].style.margin = EdgeInsets .only (top: newInternalMargin);
578
+ tree.children[i].style.margin =
579
+ EdgeInsets .only (top: newInternalMargin);
545
580
} else {
546
581
tree.children[i].style.margin =
547
582
tree.children[i].style.margin.copyWith (top: newInternalMargin);
@@ -584,7 +619,8 @@ class HtmlParser extends StatelessWidget {
584
619
585
620
tree.children? .forEach ((child) {
586
621
if ((child.style.fontSize? .size ?? parentFontSize) < 0 ) {
587
- child.style.fontSize = FontSize (parentFontSize * - child.style.fontSize.size);
622
+ child.style.fontSize =
623
+ FontSize (parentFontSize * - child.style.fontSize.size);
588
624
}
589
625
590
626
_processFontSize (child);
@@ -639,7 +675,7 @@ class ContainerSpan extends StatelessWidget {
639
675
width: style? .width,
640
676
padding: style? .padding,
641
677
margin: style? .margin,
642
- alignment: shrinkWrap? null : style? .alignment,
678
+ alignment: shrinkWrap ? null : style? .alignment,
643
679
child: child ??
644
680
RichText (
645
681
text: TextSpan (
0 commit comments