Skip to content
Discussion options

You must be logged in to vote

Further to what Will says, you could build the kind of viewer you had in mind with something like this:

from pathlib import Path
from webbrowser import open

from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Markdown, MarkdownViewer

class LinkableMarkdownViewer(MarkdownViewer):

    @on(Markdown.LinkClicked)
    def handle_link(self, event: Markdown.LinkClicked) -> None:
        if not Path(event.href).exists():
            event.prevent_default()
            open(event.href)

class LinkyMDViewer(App[None]):

    def compose(self) -> ComposeResult:
        yield LinkableMarkdownViewer("""\
# Example document

[Here is a link](https://www.exampl…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by davep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3817 on December 08, 2023 14:55.