Enable "pathlike" locations for the Markdown viewer

This commit is contained in:
Dave Pearson
2023-02-15 09:55:20 +00:00
parent 013f6cbc3f
commit 96a53d56d7
2 changed files with 4 additions and 4 deletions

View File

@@ -12,7 +12,7 @@ class MarkdownApp(App):
("f", "forward", "Forward"),
]
path = var(str(Path(__file__).parent / "demo.md"))
path = var(Path(__file__).parent / "demo.md")
@property
def markdown_viewer(self) -> MarkdownViewer:

View File

@@ -1,6 +1,6 @@
from __future__ import annotations
from pathlib import Path
from pathlib import Path, PurePath
from typing import Iterable
from markdown_it import MarkdownIt
@@ -37,7 +37,7 @@ class Navigator:
return Path(".")
return self.stack[self.index]
def go(self, path: str) -> Path:
def go(self, path: str | PurePath) -> Path:
"""Go to a new document.
Args:
@@ -749,7 +749,7 @@ class MarkdownViewer(Vertical, can_focus=True, can_focus_children=True):
if self._markdown is not None:
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."""
return await self.document.load(self.navigator.go(location))