Skip to content

Commit d955ddb

Browse files
authored
🔀 Merge pull request #71 from davep/handle-other-text
Don't attempt to render plain text
2 parents a4570a9 + cb19d2e commit d955ddb

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
- Added the MIME type of the document to the viewer's status bar.
88
([#70](https://github.com/davep/rogallo/pull/70))
9+
- Handle showing plain text content without attempting to render it as
10+
Gemtext. ([#71](https://github.com/davep/rogallo/pull/71))
911

1012
## v0.4.0
1113

src/rogallo/screens/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,10 @@ def check_action(self, action: str, parameters: tuple[object, ...]) -> bool | No
247247
return len(self._location_history) > 0 or None
248248
if action in (Reload.action_name(), CopyLocationToClipboard.action_name()):
249249
return bool(self._viewer.document.location)
250-
if action in (CopyDocumentToClipboard.action_name(), ToggleView.action_name()):
250+
if action == CopyDocumentToClipboard.action_name():
251251
return bool(self._viewer.document)
252+
if action == ToggleView.action_name():
253+
return bool(self._viewer.document) and self._viewer.is_viewing_gemtext
252254
return True
253255

254256
async def _handle_input_request(self, location: GeminiURI, sensitive: bool) -> None:
@@ -554,7 +556,8 @@ def action_copy_document_to_clipboard_command(self) -> None:
554556

555557
def action_toggle_view_command(self) -> None:
556558
"""Toggle the view between rendered and source."""
557-
self._viewer.view_source = not self._viewer.view_source
559+
if self._viewer.is_viewing_gemtext:
560+
self._viewer.view_source = not self._viewer.view_source
558561

559562

560563
### main.py ends here

src/rogallo/widgets/viewer/widget.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
##############################################################################
2222
# Local imports.
23-
from ...types import GeminiLocation
23+
from ...types import GEMINI_MIME_TYPE, GeminiLocation
2424
from .document_view import DocumentView
2525
from .gemtext_blocks import GemtextLink, GemtextWidget, get_block_widget
2626
from .status import ViewerStatus
@@ -69,6 +69,14 @@ def __bool__(self) -> bool:
6969
_status = query_one(ViewerStatus)
7070
"""The status bar widget."""
7171

72+
@property
73+
def is_viewing_gemtext(self) -> bool:
74+
"""`True` if the viewer is showing a Gemtext document, `False` otherwise.
75+
76+
Note that this is regardless of the 'view source' status.
77+
"""
78+
return self.document.mime_type == GEMINI_MIME_TYPE
79+
7280
def compose(self) -> ComposeResult:
7381
"""Compose the viewer widget."""
7482
yield ViewerTitle()
@@ -81,7 +89,7 @@ async def _watch_document(self) -> None:
8189
self._status.mime_type = self.document.mime_type or ""
8290
await self._view.remove_children()
8391
blocks: list[Static] | list[GemtextWidget]
84-
if self.view_source:
92+
if (self.document.mime_type != GEMINI_MIME_TYPE) or self.view_source:
8593
blocks = [Static(self.document.content, markup=False)]
8694
else:
8795
for widget in (

0 commit comments

Comments
 (0)