From 146891ea5bf477ba711e9b0935825f2f6db7aaa7 Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Sun, 6 Sep 2020 13:52:37 -0500 Subject: pull gemini code into its own module --- browser.py | 125 ++++--------------------------------------------------------- gemini.py | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 118 deletions(-) create mode 100644 gemini.py diff --git a/browser.py b/browser.py index 9d1d421..e0868b3 100644 --- a/browser.py +++ b/browser.py @@ -1,118 +1,8 @@ import sys -import socket -import ssl from PySide2 import QtCore, QtWidgets -def htmlescape(text): - return text.replace('<', '<').replace('>', '>') - -def gem2html(gem): - html = [] - state = 'text' - blanklines = 0 - for line in gem.split('\n'): - if line.startswith('```'): - if state == 'pre': - newstate = 'text' - blanklines = 0 - else: - newstate = 'pre' - elif state == 'pre': - newstate = 'pre' - elif line.startswith('=>'): - newstate = 'links' - elif line.startswith('* '): - newstate = 'list' - else: - newstate = 'text' - - if state != 'pre': - if len(line.strip()) == 0: - blanklines += 1 - if blanklines > 1: - html.append('
') - continue - blanklines = 0 - - if state != newstate: - if state in ('links', 'list'): - html.append('') - elif state == 'pre': - html.append('') - - if newstate in ('links', 'list'): - html.append('') + elif state == 'pre': + html.append('') + + if newstate in ('links', 'list'): + html.append('