-
Hello, I'm trying to update textual (from 3.3.0) to 5.0 and I'm having strange issues with Markdown (4.0 behaves as expected). MarkdownViewerIt's likely that my approach to Existing logicI'm subclassing class ContentWindow(MarkdownViewer):
ALLOW_MAXIMIZE = True
BINDINGS = [...]
def __init__(self, content=None, **kwargs):
self.content = content if content is not None else welcome_content
super().__init__(
self.content,
classes="content",
show_table_of_contents=False,
id="content",
**kwargs,
)
def action_up(self) -> None:
self.document.scroll_up()
def action_down(self) -> None:
self.document.scroll_down()
def action_page_down(self) -> None:
self.document.action_page_down()
def action_page_up(self) -> None:
self.document.action_page_up()
def action_scroll_home(self) -> None:
self.document.scroll_home()
def action_scroll_end(self) -> None:
self.document.scroll_end()
def update(self, markdown: str) -> None:
self.content = markdown
self.document.update(markdown)
def action_toggle_toc(self):
self.show_table_of_contents = not self.show_table_of_contents
if not self.table_of_contents.border_title:
self.table_of_contents.border_title = "Table of Contents"
if self.show_table_of_contents:
toc = self.table_of_contents.query_one(Tree)
toc.focus()
toc.action_cursor_down()
else:
self.document.focus()
def action_yank(self):
code_blocks = re.findall(CODEBLOCK_REGEX, self.content, re.MULTILINE | re.DOTALL)
if self.app.code_block_selector.has_parent:
self.app.code_block_selector.parent.remove_children([self.app.code_block_selector])
if not code_blocks:
return
self.screen.mount(self.app.code_block_selector)
self.app.code_block_selector.set_new_options(code_blocks)
self.screen.maximize(self.app.code_block_selector)
def action_open_browser(self):
provider = self.app.active_provider.display_name
resource_type = self.app.active_resource.type.value
resource_name = self.app.active_resource.name
url = f"https://search.opentofu.org/provider/{provider}/latest/docs/{resource_type}s/{resource_name}"
self.app.open_url(url)
# Without this, the Markdown viewer would try to open a file on a disk, while the Markdown itself will open a browser link (desired)
async def go(self, location):
return None The focusable throughout my app is always the document (or toc), not the Viewer. ErrorThe problem is, I'm unable to navigate the document at all. None of my custom actions work, basic arrows don't work. Even if I try to focus the I went through the Changelog and I don't see how any of those could've had this impact. Syntax highlightingAnother thing I have a problem with is probably more of a feedback. I understand the appeal of using CSS in the Markdown code blocks, but in practice, the code blocks are MUCH harder to customize and don't produce the expected colors (e.g. with builtin dracula theme). I even allowed my users to configure code block highlighting separately from the application, because pygments offer more options and they actually end up looking as they should. Re-adding |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Some of the internals have changed. We would need an MRE to understand what is impacting you. Does "markdown.py" in the examples directory work for you? As for syntax highlighting, you will have to elaborate on what you are expecting in terms of colors. |
Beta Was this translation helpful? Give feedback.
-
Are you sure your bindings worked in Textual v3.3.0? I haven't really dived into this yet, but pretty sure you'd want to scroll the |
Beta Was this translation helpful? Give feedback.
Good call.
I found two breaking changes that applied to my code.
First, I was stealing the key actions, then calling them on document. In 5.0, they shouldn't be on document. Solution = rely on builtin actions for navigation, so keep the additional bindings (in my case VIM-like), but no additional functions needed.
Second, which was less obvious - previously the way to edit css of MarkdownViewer, as well as border titles and subtitles, was again through the document. This is no longer the case and
classes
,border_title
andborder_subtitle
should be changed on the viewer level. For some reason when set on the document, the scrolling functions just break completely 🤷Overall the changes are …