summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--browset.css7
-rwxr-xr-xbrowset.py2
-rw-r--r--gemtext.py14
3 files changed, 21 insertions, 2 deletions
diff --git a/browset.css b/browset.css
index d965878..c729e54 100644
--- a/browset.css
+++ b/browset.css
@@ -19,3 +19,10 @@
 }
 .h3.header {
 }
+Preformatted {
+		height: auto;
+		border: round white;
+}
+Preformatted > Static {
+		width: auto;
+}
diff --git a/browset.py b/browset.py
index c0f55ec..f812acc 100755
--- a/browset.py
+++ b/browset.py
@@ -14,7 +14,7 @@ class Browset(App):
         Binding("ctrl+c,ctrl+q", "app.quit", "Quit", show=True),
     ]
 
-    content = ["#h1", "## hey [b]Is this unformatted?[/b]", "yeah","#h1", "### h3"]
+    content = ["#h1", "## hey [b]Is this unformatted?[/b]", "```startpre","in preformatted text this hsould have a scrollbar if it is too wide oh yeah tonight is gonna be great.", "``` (ended pre)", "afterward"]
     def compose(self) -> ComposeResult:
         yield Footer()
         yield Container(
diff --git a/gemtext.py b/gemtext.py
index 5c28e16..602d308 100644
--- a/gemtext.py
+++ b/gemtext.py
@@ -4,17 +4,26 @@ from textual.containers import Container
 
 class Gemtext(Static):
     """Gemtext widget."""
+    inPre = False
 
     def __init__(self, fp, id):
         super().__init__(id=id)
         self.addlines(fp)
+
     def addlines(self, fp):
         for lin in fp:
             line = lin
             if type(line) is bytes:
                 line = line.decode("UTF-8")
             line = line.rstrip("\r\n")
-            if line.startswith("=>"):
+            if line.startswith("```"):
+                self.inPre = not self.inPre
+                if self.inPre:
+                    self.inPre = Preformatted()
+                    self.mount(self.inPre)
+            elif self.inPre:
+                self.inPre.mount(Static(line, markup=False))
+            elif line.startswith("=>"):
                 path = line[2:].lstrip().split(' ')[0]
                 text = ' '.join(line[2:].lstrip().split(' ')[1:])
                 self.mount(Button(text or path, name=path))
@@ -25,6 +34,9 @@ class Gemtext(Static):
             else:
                 self.mount(Static(line, markup=False))
 
+class Preformatted(Container):
+    pass
+
 if __name__ == "__main__":
     from textual.app import App
     class Test(App):