Handle link taps #241
-
It would be great if there was a way to handle link taps within my own application as opposed to having swift-markdown-ui handle it for me. This would allow for applications that set a custom browser to work, as well as in app browsers to work as well. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @fishcharlie, You can set a custom action to handle links in the Markdown {
"""
Visit the [terms](https://www.example.com) and [conditions](https://apple.com).
"""
}
.environment(\.openURL, OpenURLAction { url in
// Modify a state, execute an action, etc., based on 'url'
return .handled
}) The example swift-markdown-ui/Examples/Demo/Demo/RepositoryReadmeView.swift Lines 126 to 140 in 5f977ba |
Beta Was this translation helpful? Give feedback.
Hi @fishcharlie,
You can set a custom action to handle links in the
openURL
environment value.The example
Demo
application uses this technique in theRepository README
section to scroll to the corresponding heading when the user taps an anchor link instead of opening it in Safari:swift-markdown-ui/Examples/Demo/Demo/RepositoryReadmeView.swift
Lines 126 to 140 in 5f977ba