mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 18:38:11 +02:00
Client: Mermaid diagrams, drawn by the server
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
292614c696
commit
f99b227cc3
9 files changed
+446
-16
No files matched your search
+20
-13
@@ -2,7 +2,7 @@
|
||||
EditorView/ImageView idea, with SaraView's View/Edit/Save toolbar).
|
||||
|
||||
- Markdown is rendered in View; the other text types are shown as
|
||||
highlighted code. Edit is a plain monospace field with an explicit Save
|
||||
highlighted code. On a server, ```mermaid blocks show as diagrams (Diagrams.py). Edit is a plain monospace field with an explicit Save
|
||||
(Ctrl+S). On a server, saving records line blame for you, like the web view.
|
||||
- With Markdown editing set to Live (Settings > General), Markdown opens in
|
||||
LiveMarkdown instead: rendered, and click a block to edit it in place.
|
||||
@@ -20,6 +20,7 @@ import flet as ft
|
||||
|
||||
from App import App
|
||||
from Core import ChipButton, CodeStyleSheet, HumanSize, MarkdownCodeTheme, MarkdownSheet, Palette
|
||||
from Diagrams import MaybeDiagram, WithDiagrams
|
||||
from LiveMarkdown import LiveMarkdown
|
||||
from Sources import Entry, SourceError, TextFileTypes
|
||||
|
||||
@@ -121,7 +122,8 @@ class FileView(ft.Container):
|
||||
self.TextField.value = self.Content
|
||||
if self.IsLive:
|
||||
self.Live = LiveMarkdown(self.Content, self.TheApp.Config.FontSize, self._OnTextChanged,
|
||||
self.OnFocusChange, self._OnTapLink)
|
||||
self.OnFocusChange, self._OnTapLink,
|
||||
MakeDiagram=lambda Text, Size: MaybeDiagram(self.TheApp, Text, Size))
|
||||
return self.Live
|
||||
return self._RenderedView()
|
||||
if self.FileType == "image":
|
||||
@@ -133,16 +135,21 @@ class FileView(ft.Container):
|
||||
|
||||
def _RenderedView(self) -> ft.Control:
|
||||
Text = self.TextField.value or ""
|
||||
Views: Optional[list[ft.Control]] = None
|
||||
if self.FileType == "markdown" and len(Text) <= HighlightCharLimit:
|
||||
View: ft.Control = ft.Markdown(
|
||||
value=Text,
|
||||
selectable=True,
|
||||
extension_set=ft.MarkdownExtensionSet.GITHUB_FLAVORED,
|
||||
md_style_sheet=MarkdownSheet(self.TheApp.Config.FontSize),
|
||||
code_theme=MarkdownCodeTheme(),
|
||||
code_style_sheet=CodeStyleSheet(),
|
||||
on_tap_link=self._OnTapLink,
|
||||
)
|
||||
def MakeMarkdown(Part: str) -> ft.Control:
|
||||
return ft.Markdown(
|
||||
value=Part,
|
||||
selectable=True,
|
||||
extension_set=ft.MarkdownExtensionSet.GITHUB_FLAVORED,
|
||||
md_style_sheet=MarkdownSheet(self.TheApp.Config.FontSize),
|
||||
code_theme=MarkdownCodeTheme(),
|
||||
code_style_sheet=CodeStyleSheet(),
|
||||
on_tap_link=self._OnTapLink,
|
||||
)
|
||||
|
||||
Views = WithDiagrams(self.TheApp, Text, self.TheApp.Config.FontSize, MakeMarkdown)
|
||||
View: ft.Control = Views[0]
|
||||
elif self.FileType in ("config", "html") and len(Text) <= HighlightCharLimit:
|
||||
Extension = "." + self.Item.Name.rsplit(".", 1)[-1].lower()
|
||||
View = ft.Markdown(
|
||||
@@ -156,8 +163,8 @@ class FileView(ft.Container):
|
||||
else:
|
||||
View = ft.Text(Text, selectable=True, size=self.TheApp.Config.FontSize)
|
||||
if not Text:
|
||||
View = ft.Text("This file is empty.", color=Palette.Overlay0, italic=True)
|
||||
return ft.Column([View], scroll=ft.ScrollMode.AUTO, expand=True)
|
||||
View, Views = ft.Text("This file is empty.", color=Palette.Overlay0, italic=True), None
|
||||
return ft.Column(Views or [View], scroll=ft.ScrollMode.AUTO, expand=True)
|
||||
|
||||
def _InfoView(self) -> ft.Control:
|
||||
Icon = ft.Icons.MOVIE_OUTLINED if self.FileType == "video" else ft.Icons.INSERT_DRIVE_FILE_OUTLINED
|
||||
|
||||
Reference in new issue
Block a user