diff options
-rw-r--r-- | gemini.py | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -13,12 +13,13 @@ def htmlescape(text: str) -> str: def gem2html(gem: str) -> str: html = io.StringIO() - html.write('<html>\n<head>\n<style type="text/css">\n') - html.write(open('style.css').read()) + html.write('<!DOCTYPE html>\n<html lang="en">\n<html>\n<head>\n<meta charset="utf-8"/>\n<style type="text/css">\n') + html.write(open('style.css', encoding='utf8').read()) html.write('</style>\n</head>\n<body>\n<div id="root">') parser = fsm.Parser(gem.split('\n'), html) parser.parse() html.write('</div>\n</body>\n</html>') + print(html.getvalue()) return html.getvalue() @@ -76,7 +77,12 @@ def _get(url: str) -> dict: ssock.sendall('{url}\r\n'.format(url=url).encode('utf8')) fp = ssock.makefile(mode='rb') header = fp.readline(1027) - status, meta = header.decode('utf8').split(None, 1) + parts = header.decode('utf8').split(None, 1) + status = parts[0] + if len(parts) == 1: + meta = '' + else: + meta = parts[1] if status[0] != '2': return { 'status': status, |