From dc40aacd148ecc7bf3b3050a47512803b8353409 Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Sat, 5 Sep 2020 16:36:27 -0500 Subject: initial commit --- browser.py | 220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 browser.py (limited to 'browser.py') diff --git a/browser.py b/browser.py new file mode 100644 index 0000000..9d1d421 --- /dev/null +++ b/browser.py @@ -0,0 +1,220 @@ +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('