gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.45k stars 302 forks source link

Allow links to have custom actions #52

Closed ericlewis closed 2 years ago

ericlewis commented 3 years ago

Instead of popping the user out to safari, it would be nice to allow users to be linked into a tool like BetterSafariView

ericlewis commented 3 years ago

it appears that it should be possible, but the AttributedText framework will need to be updated / expose the functionality to MarkdownUI.

gonzalezreal commented 3 years ago

Doesn't this do the job? https://developer.apple.com/documentation/swiftui/menu/onopenurl(perform:)

antonjazz commented 3 years ago

@gonzalezreal, I actually just used that with MarkdownUI in the latest version of an app I released, as a way of using links to navigate from one MarkDown page to another within the app. Works great. :)

Though I can understand that @ericlewis would want a way of directing standard http:// links to something other than Safari.

AndyIbanez commented 3 years ago

@gonzalezreal, I actually just used that with MarkdownUI in the latest version of an app I released, as a way of using links to navigate from one MarkDown page to another within the app. Works great. :)

Though I can understand that @ericlewis would want a way of directing standard http:// links to something other than Safari.

Yeah, this is the use I have as well. The service I'm writing an app for has custom rules for markdown, and when you press a URL that links to something within the service itself, it's supposed to use the to navigate to that content instead of opening Safari.

I have a workaround for this, and it's simply to replace all the appearances of https://thewebsite.com with websitescheme:// and handle the URL that way.

ericlewis commented 3 years ago

Yeah, quite aware of the workaround here. Though very undesirable. I am pretty sure I understand at least how to implement this, so it I get the time I shall.

gonzalezreal commented 3 years ago

It looks like the onOpenURL SwiftUI API is not enough to cover this use case. I will think about possible solutions. Any feedback is welcome. Thanks!

gonzalezreal commented 2 years ago

Hi @ericlewis, MarkdownUI 1.0.0 now provides custom link handling. You will find a couple of examples in the README and the documentation.