-
|
Is this possible? These links currently do not seem to get rendered: I also notice that Fortunately enough, it seems that Finally, is this how I can customize the action when a user clicks on a link in the MarkdownViewer? @on(Markdown.LinkClicked)
def go(self, event: Markdown.LinkClicked) -> None:
# do something with the event |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
The Markdown widget just handles Markdown; not Rich style links and not HTML. |
Beta Was this translation helpful? Give feedback.
-
|
Here's what I have yet: from __future__ import annotations
import logging
from pathlib import Path
from typing import TYPE_CHECKING
from textual import on
from textual._path import CSSPathType
from textual.app import App, ComposeResult, CSSPathType
from textual.containers import ScrollableContainer
from textual.widgets import Footer, Header, Input, MarkdownViewer, Markdown
WELCOME = """
# Welcome
To view documentation for a package, module, class,
or any other documented object, try typing its Python path
in the search bar at the top.
By *Python path*, we mean for example `package.module.Class`
or `package.function`.
Testing [links](#hello).
"""
class CustomMarkdownViewer(MarkdownViewer):
async def _on_markdown_link_clicked(self, message: Markdown.LinkClicked) -> None:
message.stop()
try:
await self.go(message.href)
except Exception as error:
# error is a proper FileNotFoundError
message.stop(stop=False)
class GriffeTUIApp(App):
"""A Textual app to visualize docs collected by Griffe."""
BINDINGS = [
("d", "toggle_dark", "Toggle dark mode"),
]
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield Header()
yield CustomMarkdownViewer(WELCOME, id="page")
yield Footer()
def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
@on(Markdown.LinkClicked)
def go(message: Markdown.LinkClicked) -> None:
print(message.href)It seems to never get into my own I've just started using Textual so forgive my intuitions 😅 |
Beta Was this translation helpful? Give feedback.

The Markdown widget just handles Markdown; not Rich style links and not HTML.