mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Enable "pathlike" locations for the Markdown viewer
This commit is contained in:
@@ -12,7 +12,7 @@ class MarkdownApp(App):
|
|||||||
("f", "forward", "Forward"),
|
("f", "forward", "Forward"),
|
||||||
]
|
]
|
||||||
|
|
||||||
path = var(str(Path(__file__).parent / "demo.md"))
|
path = var(Path(__file__).parent / "demo.md")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def markdown_viewer(self) -> MarkdownViewer:
|
def markdown_viewer(self) -> MarkdownViewer:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path, PurePath
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
from markdown_it import MarkdownIt
|
from markdown_it import MarkdownIt
|
||||||
@@ -37,7 +37,7 @@ class Navigator:
|
|||||||
return Path(".")
|
return Path(".")
|
||||||
return self.stack[self.index]
|
return self.stack[self.index]
|
||||||
|
|
||||||
def go(self, path: str) -> Path:
|
def go(self, path: str | PurePath) -> Path:
|
||||||
"""Go to a new document.
|
"""Go to a new document.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -749,7 +749,7 @@ class MarkdownViewer(Vertical, can_focus=True, can_focus_children=True):
|
|||||||
if self._markdown is not None:
|
if self._markdown is not None:
|
||||||
await self.document.update(self._markdown)
|
await self.document.update(self._markdown)
|
||||||
|
|
||||||
async def go(self, location: str) -> bool:
|
async def go(self, location: str | PurePath) -> bool:
|
||||||
"""Navigate to a new document path."""
|
"""Navigate to a new document path."""
|
||||||
return await self.document.load(self.navigator.go(location))
|
return await self.document.load(self.navigator.go(location))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user