Add option to catch unhandled meta links with custom logic using a signal.
Right now unhandled links default to being used as "https://" + meta and instead I think there should be emitted as a signal so another script can listen for the link click
The use for this would be for maybe having a different script load something, or showing a tooltip. Just a way to have a different script listen for a click and then responding to it.
Here's a rough example:
# a new signal for handling unhandled links
signal unhandled_link(meta)
@export var automatic_links := true
# new toggle for the signal option
@export var emit_signal_for_unhandled_links := true;
func _on_meta_clicked(meta: Variant) -> void:
if not automatic_links:
return
# ... same as before ...
if emit_signal_for_unhandled_links:
unhandled_link.emit(meta)
else:
# original implementation
OS.shell_open("https://" + meta)
This would allow for link click logic to be handled by a different class, for example one that shows like... a tooltip, or shows a different page.
You could also use a non Markdown custom handler. For example I initially used f^ to denote a desire to call a function
[Hello Click Me!](f^ShowAlert)
signal link_signal(meta)
func _on_meta_clicked(meta: Variant) -> void:
if meta.begins_with("f^"):
link_signal.emit(meta)
Just an idea I had after using it for a bit
That makes sense, thanks for the example. I'll take a look at this when I prepare the next update.
Implemented in https://github.com/daenvil/MarkdownLabel/commit/bd6378f42b9de9e68560a19d70b2d05ec60c2bf8
Now a unhandled_link_clicked signal is emitted whenever the node does not handle a link.
A new assume_https_links property was added, which can be used to disable/enable the behavior of defaulting to "https://" + link.