NuPlay / RichText

Easily show RichText(html) in SwiftUI
MIT License
209 stars 36 forks source link

LinkOpenType - custom type #46

Closed mauryalamin closed 7 months ago

mauryalamin commented 7 months ago

Could be my inexperience, but I was hoping to use this new feature in the following way:

  1. I receive HTML content via an api
  2. The HTML contains links that I would like to open within my app, using it to display the content in my UI (not in any browser)
  3. Some of the links from this api come in weird formats like "<a href=\"/gary-busey/4005-1780/\" data-ref-id=\"4005-1780\">Gary Busey"
  4. I was planning to process the link using Regex to rewrite it and load the content in a new view in my app
  5. I tried some simple test code like:
    .linkOpenType(.custom({ url in
      print(url)
    }))

    but I'm getting the following messages in the Output window after clinking the link:

    0x16e1300c0 - [PID=77634] WebProcessProxy::checkURLReceivedFromWebProcess: Received an unexpected URL from the web process
    0x1060a9018 - [pageProxyID=14, webPageID=15, PID=77634] WebPageProxy::Ignoring request to load this main resource because it is outside the sandbox

If I click a traditional-looking link like: <a href=\"https://api.site.com/gary-busey/4005-15789/\" data-ref-id=\"4005-15789\">Gary Busey My code will print the URL as expected.

Am I totally off base, trying to use the new feature in this way? If so, what's the intended use of this feature?

Thanks Maury

NuPlay commented 7 months ago

Thank you for pointing out the issue. Initially, when linkOpenType was set to custom, it returned links only for http and https schemes.

Recognizing the limitation, I've now made a modification in the new branch, feature/#46-change-customtype.

With this update, setting linkOpenType to 'custom' will ensure that links are returned for all url schemes.

Please test this change in the specified branch and confirm if it works as intended.

mauryalamin commented 7 months ago

I tested the change and it is working as expected.

Thanks!!!