Skip to content

Commit a733289

Browse files
committed
Fixes #515 by properly, recursively applying linking and styling to text spans inside <a> tags
1 parent e2a9933 commit a733289

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

lib/html_parser.dart

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -336,37 +336,48 @@ class HtmlParser extends StatelessWidget {
336336
);
337337
}
338338
} else if (tree is InteractableElement) {
339+
InlineSpan addTaps(InlineSpan childSpan, TextStyle childStyle) {
340+
if (childSpan is TextSpan) {
341+
return TextSpan(
342+
text: childSpan.text,
343+
children: childSpan.children
344+
?.map((e) => addTaps(e, childStyle.merge(childSpan.style)))
345+
?.toList(),
346+
style: newContext.style.generateTextStyle().merge(
347+
childSpan.style == null
348+
? childStyle
349+
: childStyle.merge(childSpan.style)),
350+
// style: (childSpan.style ?? TextStyle())
351+
// .merge(newContext.style.generateTextStyle()),
352+
semanticsLabel: childSpan.semanticsLabel,
353+
recognizer: TapGestureRecognizer()
354+
..onTap = () => onLinkTap?.call(tree.href),
355+
);
356+
} else {
357+
return WidgetSpan(
358+
child: RawGestureDetector(
359+
gestures: {
360+
MultipleTapGestureRecognizer:
361+
GestureRecognizerFactoryWithHandlers<
362+
MultipleTapGestureRecognizer>(
363+
() => MultipleTapGestureRecognizer(),
364+
(instance) {
365+
instance..onTap = () => onLinkTap?.call(tree.href);
366+
},
367+
),
368+
},
369+
child: (childSpan as WidgetSpan).child,
370+
),
371+
);
372+
}
373+
}
374+
339375
return TextSpan(
340376
children: tree.children
341377
.map((tree) => parseTree(newContext, tree))
342378
.map((childSpan) {
343-
if (childSpan is TextSpan) {
344-
return TextSpan(
345-
text: childSpan.text,
346-
children: childSpan.children,
347-
style: (childSpan.style ?? TextStyle())
348-
.merge(newContext.style.generateTextStyle()),
349-
semanticsLabel: childSpan.semanticsLabel,
350-
recognizer: TapGestureRecognizer()
351-
..onTap = () => onLinkTap?.call(tree.href),
352-
);
353-
} else {
354-
return WidgetSpan(
355-
child: RawGestureDetector(
356-
gestures: {
357-
MultipleTapGestureRecognizer:
358-
GestureRecognizerFactoryWithHandlers<
359-
MultipleTapGestureRecognizer>(
360-
() => MultipleTapGestureRecognizer(),
361-
(instance) {
362-
instance..onTap = () => onLinkTap?.call(tree.href);
363-
},
364-
),
365-
},
366-
child: (childSpan as WidgetSpan).child,
367-
),
368-
);
369-
}
379+
return addTaps(childSpan,
380+
newContext.style.generateTextStyle().merge(childSpan.style));
370381
}).toList() ??
371382
[],
372383
);

0 commit comments

Comments
 (0)