Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- Added a `ToggleCosyLinkNumbers` command, which moves the link jump numbers
over to the left of the link text or back to the right.
([#193](https://github.com/davep/rogallo/pull/193))
- Modified `ToggleEmojiRemoval` so that it *doesn't* remove emojis from
pre-formatted text. ([#196](https://github.com/davep/rogallo/pull/196))

## v0.11.0

Expand Down
14 changes: 14 additions & 0 deletions src/rogallo/widgets/viewer/content_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class GemtextContent:

_filter: ContentFilter = ContentFilter(str)
"""The content filter."""
_purely_ansi_filter: ContentFilter = ContentFilter(str)
"""A content filter that only deals with ANSI escape sequences."""

@staticmethod
def _strip_ansi(text: str) -> str:
Expand Down Expand Up @@ -64,12 +66,15 @@ def set_filter(
strip_emoji: Whether to strip emoji from the content.
"""
cls._filter = ContentFilter(str)
cls._purely_ansi_filter = ContentFilter(str)
if strip_emoji:
cls._filter |= cls._strip_emoji
if allow_ansi_escape_sequences:
cls._filter |= Text.from_ansi
cls._purely_ansi_filter |= Text.from_ansi
else:
cls._filter |= cls._strip_ansi
cls._purely_ansi_filter |= cls._strip_ansi

@classmethod
def filter(cls, line: Line) -> str | Text:
Expand All @@ -80,5 +85,14 @@ def filter(cls, line: Line) -> str | Text:
"""
return cls._filter(line)

@classmethod
def ansi_filter(cls, line: Line) -> str | Text:
"""Filter a Gemtext line, affecting only ANSI escape sequences.

Returns:
The filtered line content.
"""
return cls._purely_ansi_filter(line)


### content_filter.py ends here
2 changes: 1 addition & 1 deletion src/rogallo/widgets/viewer/gemtext_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def __init__(self, preformatted: Line) -> None:

def compose(self) -> ComposeResult:
"""Compose the Gemtext preformatted text widget."""
text = GemtextContent.filter(self._preformatted)
text = GemtextContent.ansi_filter(self._preformatted)
yield Label(
highlight(
str(text),
Expand Down
Loading