diff options
| author | Zach DeCook <zachdecook@librem.one> | 2022-12-10 14:30:23 -0500 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2022-12-10 14:30:23 -0500 |
| commit | a2707df86fcd7541840f2f3091953b717a6a101b (patch) | |
| tree | 3881d6045756f4cafd37827ec9cd313b0b3eac06 /gemtext.py | |
| parent | db8880b82dafde1392edda7e1cf73f321cb6bb88 (diff) | |
| download | browset-a2707df86fcd7541840f2f3091953b717a6a101b.tar.gz | |
widgets: Create widget to render gemtext
Diffstat (limited to 'gemtext.py')
| -rw-r--r-- | gemtext.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gemtext.py b/gemtext.py new file mode 100644 index 0000000..df8402c --- /dev/null +++ b/gemtext.py @@ -0,0 +1,27 @@ +from textual.widgets import Button, Static +from textual.app import ComposeResult +from textual.containers import Container + +class Gemtext(Static): + """Gemtext widget.""" + items = [] + def compose(self) -> ComposeResult: + yield Container(*self.items) + + def __init__(self, txt): + super().__init__() + for line in txt.split('\n'): + if line.startswith("=>"): + path = line[2:].lstrip().split(' ')[0] + text = ' '.join(line[2:].lstrip().split(' ')[1:]) + self.items.append(Button(text or path, name=path)) + else: + self.items.append(Static(line)) + +if __name__ == "__main__": + from textual.app import App + class Test(App): + def compose(self) -> ComposeResult: + yield Gemtext(txt="#title\n=> /href link text\nworld star hiphop") + app = Test() + app.run() |
