summaryrefslogtreecommitdiff
path: root/gemini.py
diff options
context:
space:
mode:
Diffstat (limited to 'gemini.py')
-rw-r--r--gemini.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/gemini.py b/gemini.py
index beb2d5c..9856449 100644
--- a/gemini.py
+++ b/gemini.py
@@ -8,6 +8,7 @@ def htmlescape(text: str) -> str:
def gem2html(gem: str) -> str:
html = []
+ html.append('<style>\n{css}</style>'.format(css=open('style.css').read()))
state = 'text'
blanklines = 0
for line in gem.split('\n'):
@@ -50,12 +51,11 @@ def gem2html(gem: str) -> str:
pass
elif state == 'links':
tokens = line.split(None, 2)
- if len(tokens) == 3:
- _, url, text = tokens
- html.append('<li><a href="{url}">{text}</a></li>'.format(url=url, text=text))
- else:
- _, url = tokens
- html.append('<li><a href="{url}">{url}</a></li>'.format(url=url))
+ url = tokens[1]
+ text = None if len(tokens) < 3 else tokens[2]
+ url_parts = urllib.parse.urlsplit(url)
+ external = ' class="external"' if url_parts.scheme not in ('gemini', '') else ''
+ html.append('<li{external}><a href="{url}">{text}</a></li>'.format(url=url, text=text or url, external=external))
elif state == 'list':
html.append('<li>{}</li>'.format(line[2:]))
elif state == 'pre':