summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2021-10-12 14:59:40 +0200
committerLars-Dominik Braun <lars@6xq.net>2021-10-17 17:23:44 +0200
commit67901c25470734107a9888402e8e12a2c8e0a25b (patch)
treec0573c3a6a62b257ae08140115368af060e9eafc
parent0b568ab6409410aa78c28f48824b8ff5b338c3af (diff)
downloadlulua-67901c25470734107a9888402e8e12a2c8e0a25b.tar.gz
lulua-67901c25470734107a9888402e8e12a2c8e0a25b.tar.bz2
lulua-67901c25470734107a9888402e8e12a2c8e0a25b.zip
util: Improve support for invisible symbols
Auto-generate short name for them instead of having a static list.
-rw-r--r--lulua/util.py18
1 files changed, 11 insertions, 7 deletions
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)