Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.79k stars 860 forks source link

convert any link in text to hyperlink #1300

Closed hemantchauhan closed 1 year ago

hemantchauhan commented 1 year ago

Hello team,

Below is a sample html text that i am getting from our backend -

'Linking to https://www.google.com/?client=safari has never been easier.'

As there are no href tags here, the library does not convert the http links into hyperlinks. How can I achieve this?

krille-chan commented 1 year ago

I have the same problem in my app. IMO I would not expect that a html rendering library also supports detecting links. However I use the Linkify Package for this to manipulate the html string before I render it:

final linkifiedHtmlString = linkify(
      htmlString,
      options: const LinkifyOptions(humanize: false),
    ).map(
      (element) {
        if (element is! UrlElement ||
            element.text.contains('<') ||
            element.text.contains('>') ||
            element.text.contains('"')) {
          return element.text;
        }
        return '<a href="${element.url}">${element.text}</a>';
      },
    ).join('');
hemantchauhan commented 1 year ago

right. thanks @krille-chan

Sub6Resources commented 1 year ago

@krille-chan is correct