diff options
-rw-r--r-- | TODO.md | 1 | ||||
-rw-r--r-- | gemini.py | 12 | ||||
-rw-r--r-- | style.css | 3 |
3 files changed, 10 insertions, 6 deletions
@@ -8,3 +8,4 @@ - [ ] search in page - [ ] work with search pages - [x] stdlib url parsing in gemini module + - [ ] nice typography @@ -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': diff --git a/style.css b/style.css new file mode 100644 index 0000000..c4b8372 --- /dev/null +++ b/style.css @@ -0,0 +1,3 @@ +li.external a { + color: red; +} |