@@ -16,7 +16,12 @@ import 'package:html/dom.dart' as dom;
16
16
import 'package:html/parser.dart' as htmlparser;
17
17
import 'package:webview_flutter/webview_flutter.dart' ;
18
18
19
- typedef OnTap = void Function (String ? url);
19
+ typedef OnTap = void Function (
20
+ String ? url,
21
+ RenderContext ? context,
22
+ Map <String , String ?>? attributes,
23
+ dom.Element ? element,
24
+ );
20
25
typedef CustomRender = dynamic Function (
21
26
RenderContext context,
22
27
Widget parsedChild,
@@ -272,35 +277,52 @@ class HtmlParser extends StatelessWidget {
272
277
),
273
278
);
274
279
} else if (tree.style.display == Display .LIST_ITEM ) {
280
+ List <InlineSpan > getChildren (StyledElement tree) {
281
+ InlineSpan tabSpan = WidgetSpan (child: Text ("\t " , textAlign: TextAlign .right));
282
+ List <InlineSpan > children = tree.children.map ((tree) => parseTree (newContext, tree)).toList ();
283
+ if (tree.style.listStylePosition == ListStylePosition .INSIDE ) {
284
+ children.insert (0 , tabSpan);
285
+ }
286
+ return children;
287
+ }
288
+
275
289
return WidgetSpan (
276
290
child: ContainerSpan (
277
291
newContext: newContext,
278
292
style: tree.style,
279
293
shrinkWrap: context.parser.shrinkWrap,
280
- child: Stack (
294
+ child: Row (
295
+ crossAxisAlignment: CrossAxisAlignment .start,
296
+ mainAxisSize: MainAxisSize .min,
297
+ textDirection: tree.style.direction,
281
298
children: [
282
- if (tree.style.listStylePosition == ListStylePosition .OUTSIDE ||
283
- tree.style.listStylePosition == null )
284
- PositionedDirectional (
285
- width: 30 , //TODO derive this from list padding.
286
- start: 0 ,
287
- child: Text ('${newContext .style .markerContent }\t ' ,
288
- textAlign: TextAlign .right,
289
- style: newContext.style.generateTextStyle ()),
290
- ),
299
+ tree.style.listStylePosition == ListStylePosition .OUTSIDE ?
291
300
Padding (
292
- padding: EdgeInsetsDirectional .only (start: 30 ), //TODO derive this from list padding.
293
- child: StyledText (
294
- textSpan: TextSpan (
295
- text: (tree.style.listStylePosition == ListStylePosition .INSIDE )
296
- ? '${newContext .style .markerContent }\t '
297
- : null ,
298
- children: tree.children.map ((tree) => parseTree (newContext, tree)).toList (),
299
- style: newContext.style.generateTextStyle (),
300
- ),
301
- style: newContext.style,
302
- renderContext: context,
301
+ padding: tree.style.padding ?? EdgeInsets .only (left: tree.style.direction != TextDirection .rtl ? 10.0 : 0.0 , right: tree.style.direction == TextDirection .rtl ? 10.0 : 0.0 ),
302
+ child: Text (
303
+ "${newContext .style .markerContent }" ,
304
+ textAlign: TextAlign .right,
305
+ style: newContext.style.generateTextStyle ()
303
306
),
307
+ ) : Container (height: 0 , width: 0 ),
308
+ Text ("\t " , textAlign: TextAlign .right),
309
+ Expanded (
310
+ child: Padding (
311
+ padding: tree.style.listStylePosition == ListStylePosition .INSIDE ?
312
+ EdgeInsets .only (left: tree.style.direction != TextDirection .rtl ? 10.0 : 0.0 , right: tree.style.direction == TextDirection .rtl ? 10.0 : 0.0 ) : EdgeInsets .zero,
313
+ child: StyledText (
314
+ textSpan: TextSpan (
315
+ text: (tree.style.listStylePosition ==
316
+ ListStylePosition .INSIDE )
317
+ ? '${newContext .style .markerContent }'
318
+ : null ,
319
+ children: getChildren (tree),
320
+ style: newContext.style.generateTextStyle (),
321
+ ),
322
+ style: newContext.style,
323
+ renderContext: context,
324
+ )
325
+ )
304
326
)
305
327
],
306
328
),
@@ -330,7 +352,7 @@ class HtmlParser extends StatelessWidget {
330
352
: childStyle.merge (childSpan.style)),
331
353
semanticsLabel: childSpan.semanticsLabel,
332
354
recognizer: TapGestureRecognizer ()
333
- ..onTap = () => onLinkTap? .call (tree.href),
355
+ ..onTap = () => onLinkTap? .call (tree.href, context, tree.attributes, tree.element ),
334
356
);
335
357
} else {
336
358
return WidgetSpan (
@@ -341,7 +363,7 @@ class HtmlParser extends StatelessWidget {
341
363
MultipleTapGestureRecognizer >(
342
364
() => MultipleTapGestureRecognizer (),
343
365
(instance) {
344
- instance..onTap = () => onLinkTap? .call (tree.href);
366
+ instance..onTap = () => onLinkTap? .call (tree.href, context, tree.attributes, tree.element );
345
367
},
346
368
),
347
369
},
@@ -489,7 +511,7 @@ class HtmlParser extends StatelessWidget {
489
511
static StyledElement _processListCharactersRecursive (
490
512
StyledElement tree, ListQueue <Context <int >> olStack) {
491
513
if (tree.name == 'ol' ) {
492
- olStack.add (Context (0 ));
514
+ olStack.add (Context ((tree.attributes[ 'start' ] != null ? int . tryParse (tree.attributes[ 'start' ] ?? "" ) ?? 1 : 1 ) - 1 ));
493
515
} else if (tree.style.display == Display .LIST_ITEM && tree.style.listStyleType != null ) {
494
516
switch (tree.style.listStyleType! ) {
495
517
case ListStyleType .DISC :
0 commit comments