mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 02: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
@@ -6,7 +6,8 @@ another block, puts it back rendered.
|
||||
A block is what Markdown itself separates: a heading line, a fenced code
|
||||
block, a horizontal rule, or a run of lines up to a blank line (a paragraph,
|
||||
list, table or quote). The text between blocks (blank lines) is kept
|
||||
byte for byte, so editing one block never reformats the rest of the file."""
|
||||
byte for byte, so editing one block never reformats the rest of the file.
|
||||
A ```mermaid block shows as its diagram when MakeDiagram gives one (Diagrams.py)."""
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
@@ -101,7 +102,8 @@ def SplitBlocks(Document: str) -> list[Block]:
|
||||
|
||||
class LiveMarkdown(ft.Column):
|
||||
def __init__(self, Document: str, FontSize: int, OnChange: Callable[[], None],
|
||||
OnFocusChange: Callable[[bool], None], OnTapLink: Callable):
|
||||
OnFocusChange: Callable[[bool], None], OnTapLink: Callable,
|
||||
MakeDiagram: Optional[Callable[[str, int], Optional[ft.Control]]] = None):
|
||||
super().__init__(scroll=ft.ScrollMode.AUTO, expand=True, spacing=0,
|
||||
horizontal_alignment=ft.CrossAxisAlignment.STRETCH)
|
||||
self.Document = Document
|
||||
@@ -109,6 +111,7 @@ class LiveMarkdown(ft.Column):
|
||||
self.OnChange = OnChange
|
||||
self.OnFocusChange = OnFocusChange
|
||||
self.OnTapLink = OnTapLink
|
||||
self.MakeDiagram = MakeDiagram
|
||||
self.Blocks: list[Block] = []
|
||||
self.BlockControls: list[ft.Control] = []
|
||||
# Rendered blocks by their text, reused when the layout is rebuilt so
|
||||
@@ -217,8 +220,9 @@ class LiveMarkdown(ft.Column):
|
||||
# --- Rendering -------------------------------------------------------
|
||||
|
||||
def _Render(self, Text: str) -> ft.Control:
|
||||
Diagram = self.MakeDiagram(Text, self.FontSize) if self.MakeDiagram else None
|
||||
Rendered = ft.Container(
|
||||
content=ft.Markdown(
|
||||
content=Diagram or ft.Markdown(
|
||||
value=Text,
|
||||
extension_set=ft.MarkdownExtensionSet.GITHUB_FLAVORED,
|
||||
md_style_sheet=MarkdownSheet(self.FontSize),
|
||||
|
||||
Reference in new issue
Block a user