Skip to content

Commit

Permalink
Fixes Sub6Resources#515 by properly, recursively applying linking and…
Browse files Browse the repository at this point in the history
… styling to text spans inside <a> tags
  • Loading branch information
erickok committed Jan 29, 2021
1 parent e2a9933 commit a733289
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,37 +336,48 @@ class HtmlParser extends StatelessWidget {
);
}
} else if (tree is InteractableElement) {
InlineSpan addTaps(InlineSpan childSpan, TextStyle childStyle) {
if (childSpan is TextSpan) {
return TextSpan(
text: childSpan.text,
children: childSpan.children
?.map((e) => addTaps(e, childStyle.merge(childSpan.style)))
?.toList(),
style: newContext.style.generateTextStyle().merge(
childSpan.style == null
? childStyle
: childStyle.merge(childSpan.style)),
// style: (childSpan.style ?? TextStyle())
// .merge(newContext.style.generateTextStyle()),
semanticsLabel: childSpan.semanticsLabel,
recognizer: TapGestureRecognizer()
..onTap = () => onLinkTap?.call(tree.href),
);
} else {
return WidgetSpan(
child: RawGestureDetector(
gestures: {
MultipleTapGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
MultipleTapGestureRecognizer>(
() => MultipleTapGestureRecognizer(),
(instance) {
instance..onTap = () => onLinkTap?.call(tree.href);
},
),
},
child: (childSpan as WidgetSpan).child,
),
);
}
}

return TextSpan(
children: tree.children
.map((tree) => parseTree(newContext, tree))
.map((childSpan) {
if (childSpan is TextSpan) {
return TextSpan(
text: childSpan.text,
children: childSpan.children,
style: (childSpan.style ?? TextStyle())
.merge(newContext.style.generateTextStyle()),
semanticsLabel: childSpan.semanticsLabel,
recognizer: TapGestureRecognizer()
..onTap = () => onLinkTap?.call(tree.href),
);
} else {
return WidgetSpan(
child: RawGestureDetector(
gestures: {
MultipleTapGestureRecognizer:
GestureRecognizerFactoryWithHandlers<
MultipleTapGestureRecognizer>(
() => MultipleTapGestureRecognizer(),
(instance) {
instance..onTap = () => onLinkTap?.call(tree.href);
},
),
},
child: (childSpan as WidgetSpan).child,
),
);
}
return addTaps(childSpan,
newContext.style.generateTextStyle().merge(childSpan.style));
}).toList() ??
[],
);
Expand Down

0 comments on commit a733289

Please sign in to comment.