summary refs log tree commit diff
path: root/gemtext.py
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2022-12-28 20:42:12 -0500
committerZach DeCook <zachdecook@librem.one>2022-12-28 20:42:12 -0500
commit47e38e9a08e36a78bef88629c58f69cf8be89fbc (patch)
tree389115c39edfc83c34b811fe9dc0c5d2a87dcec7 /gemtext.py
parent32480497b7b7a8927ea9dd32bb09fd39e7cf9e1c (diff)
downloadbrowset-47e38e9a08e36a78bef88629c58f69cf8be89fbc.tar.gz
preformatted: Format fine (except description is not shown)
Diffstat (limited to 'gemtext.py')
-rw-r--r--gemtext.py14
1 files changed, 13 insertions, 1 deletions
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):