Skip to content

[FEATURE] Support oembed links #881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dJani97 opened this issue Oct 28, 2021 · 4 comments
Closed

[FEATURE] Support oembed links #881

dJani97 opened this issue Oct 28, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@dJani97
Copy link

dJani97 commented Oct 28, 2021

Describe your feature request

Hey!

Our API returns embedded links in the following format:

<p>There should be a YouTube video link below this</p>
<figure class="media">
   <oembed url="https://youtu.be/4FGnb2lgPBA"></oembed>
</figure> 

The current version of flutter_html simply ignores those lines and only displays the <p> tag.

Can you please give a hint on how I could parse that oembed URL into a working link with this plugin?

Since it could be anything (not only YT videos), my intention is to simply display it as a regular link:

<a href="https://youtu.be/4FGnb2lgPBA">https://youtu.be/4FGnb2lgPBA</a>

A picture of a cute animal (not mandatory but encouraged)

@dJani97 dJani97 added the enhancement New feature or request label Oct 28, 2021
@tneotia
Copy link
Contributor

tneotia commented Oct 28, 2021

You can make a customrender for the oembed tag and just render a link element with the inner contents. I recommend checking out the README which has a few examples for customrender to get a better idea.

@erickok
Copy link
Contributor

erickok commented Nov 29, 2021

Please let us know if this is an open issue still. We can provide concrete examples.

For this concrete example:

Html(
  data: r"""
    <p>There should be a YouTube video link below this</p>
    <figure class="media">
       <oembed url="https://youtu.be/4FGnb2lgPBA"></oembed>
    </figure>""",
  tagsList: Html.tags..addAll(["figure", "oembed"]),
  customRender: {
    "figure": (context, child) {
      final url = context.tree.element!.children.first.attributes["url"]!;
      return ElevatedButton(
        onPressed: () {
          // Do something with the url
        },
        child: Text(url),
      );
    },
  },
)

Which renders as:
Screenshot 2021-11-29 at 15 16 39

@erickok erickok closed this as completed Nov 29, 2021
@dJani97
Copy link
Author

dJani97 commented Nov 29, 2021

Thank you for the example, it does solve my issue, although I have to use SelectableHtml which does not support customRender yet.

Is there any way for me to use some kind of pre-release version which includes this PR?

The app I'm working on will be released soon, and it would be nice to have this feature included.

@tneotia
Copy link
Contributor

tneotia commented Nov 29, 2021

You could use a git dependency on my fork of the repo with that branch as the reference. However, since you use SelectableHtml, you cannot add "widgets" like buttons due to a limitation in Flutter.

This limitation has been fixed on the dev branch if I remember correctly, but since it hasn't hit Flutter stable yet, I haven't added the capability for users to use a WidgetSpan inside the customRender.

Thus, if you want to support oembed inside SelectableHtml, you will need to use a TextSpan with the customRender PR, so that limits you to only showing the URL text and maybe styling it to look like a hyperlink, then add the TapGestureRecognizer to the TextSpan and you can make the link open in a 3rd party application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants