summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Singleton <matt@xcolour.net>2020-09-08 13:15:43 -0500
committerMatt Singleton <matt@xcolour.net>2020-09-08 13:15:43 -0500
commitbc9004305ebc36539b7b6a699b18b02c13f9ab48 (patch)
tree881cda0c641d312e7ab0d46b2318481c5a53723d
parent407ca6b4ed2357ed6d35cd93ee3191761a9b65c5 (diff)
add a stylesheet
-rw-r--r--TODO.md1
-rw-r--r--gemini.py12
-rw-r--r--style.css3
3 files changed, 10 insertions, 6 deletions
diff --git a/TODO.md b/TODO.md
index 837dd54..112487c 100644
--- a/TODO.md
+++ b/TODO.md
@@ -8,3 +8,4 @@
- [ ] search in page
- [ ] work with search pages
- [x] stdlib url parsing in gemini module
+ - [ ] nice typography
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':
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;
+}