From a73328924b5188d305b93c5a06fd1afb50fb440f Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 29 Jan 2021 16:12:03 +0100 Subject: [PATCH 1/2] Fixes #515 by properly, recursively applying linking and styling to text spans inside tags --- lib/html_parser.dart | 65 ++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/lib/html_parser.dart b/lib/html_parser.dart index bfdd06ab77..39ba6d17df 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -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() ?? [], ); From ee3eb7355b54119a458a1580a3d08be6460cd8d6 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 29 Jan 2021 16:14:50 +0100 Subject: [PATCH 2/2] Remove comment-out temporary code --- lib/html_parser.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/html_parser.dart b/lib/html_parser.dart index 39ba6d17df..919ff36c0d 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -347,8 +347,6 @@ class HtmlParser extends StatelessWidget { 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),