gemini.git

going-flying.com gemini git repository

summary

tree

log

refs

7c16bf118e6de32479d571ce476701682adcdb53 - Matthew Ernisse - 1612457198

try a new format for links

view tree

view raw

diff --git a/files/thoughts-to-gemini.py b/files/thoughts-to-gemini.py
index 4475aad..f403472 100755
--- a/files/thoughts-to-gemini.py
+++ b/files/thoughts-to-gemini.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 # -*- coding: UTF-8 -*-
-'''thoughts-to-gemini.py (c) 2020 Matthew J Ernisse <matt@going-flying.com>
+'''thoughts-to-gemini.py (c) 2020-2021 Matthew J Ernisse <matt@going-flying.com>
 All Rights Reserved.
 
 Redistribution and use in source and binary forms,
@@ -105,7 +105,7 @@ class DeHTMLizer(object):
 
 		trailer = '\n\n'
 		for n, link in enumerate(self.links):
-			trailer += f'=> {link} [{n + 1}]\n'
+			trailer += f'=> {link} [{n + 1}] {link}\n'
 
 		return self.gemini + trailer
 
@@ -133,10 +133,11 @@ class DeHTMLizer(object):
 		if tag.name == 'a':
 			self.links.append(tag['href'])
 			num = len(self.links)
+			sNum = SuperNum(num)
 			if not tag.string:
-				return f'«{tag["href"]}[{num}]»'
+				return f'«{tag["href"]}»{sNum!s}'
 
-			return f'«{tag.string}[{num}]»'
+			return f'«{tag.string}»{sNum!s}'
 
 		elif tag.name in nestable:
 			if hasattr(tag, 'contents'):
@@ -302,6 +303,21 @@ class Thoughts(object):
 		return self._years[year][month]
 
 
+class SuperNum(object):
+	''' Return given number as unicode superscript. '''
+	_u = ['⁰', '¹', '²', '³', '⁴', '⁵', '⁶', '⁷', '⁸', '⁹']
+	def __init__(self, val):
+		try:
+			int(val):
+		except ValueError:
+			raise ValueError('Value must be a base 10 integer')
+
+		self.val = str(val)
+
+	def __str__(self):
+		return ''.join([_u[ord(ch) - 48] for ch in self.val])
+
+
 class ThoughtApi(object):
 	''' Provide an interface to my Thoughts. '''
 	imgUrl = 'https://thoughtsassets.blob.core.windows.net/thumbnails'