From 67901c25470734107a9888402e8e12a2c8e0a25b Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 12 Oct 2021 14:59:40 +0200 Subject: util: Improve support for invisible symbols Auto-generate short name for them instead of having a static list. --- lulua/util.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lulua') diff --git a/lulua/util.py b/lulua/util.py index 5d7ea1b..0245275 100644 --- a/lulua/util.py +++ b/lulua/util.py @@ -22,7 +22,7 @@ Misc utilities """ -import os, yaml, pkg_resources, unicodedata +import os, yaml, pkg_resources, unicodedata, re first = lambda x: next (iter (x)) @@ -79,16 +79,20 @@ def displayText (text): if all (map (lambda x: unicodedata.combining (x) != 0, text)): # add circle if combining return '\u25cc' + text + if len (text) == 1 and unicodedata.category (text) == 'Cf': + stopwords = re.compile('\WTO\W', re.I) + try: + cleanName = unicodedata.name (text).replace ('-', ' ') + short = ''.join (map (lambda x: x[0], stopwords.sub(' ', cleanName).split (' '))) + return f'[{short}]' + except ValueError: + # No such name. + pass invMap = { '\t': '⭾', '\n': '↳', ' ': '\u2423', '\b': '⌦', - '\u200e': '[LRM]', # left to right mark - '\u061c': '[ALM]', # arabic letter mark - '\u202c': '[PDF]', # pop directional formatting - "\u2066": '[LRI]', # left-to-right isolate (lri) - "\u2067": '[RLI]', # right-to-left isolate (rli) - "\u2069": '[PDI]', # pop directional isolate (pdi) + '\u202f': '[NNBSP]', } return invMap.get (text, text) -- cgit v1.2.3