From 976055c5c7b25d31f8afa82d55a809091c11eedd Mon Sep 17 00:00:00 2001 From: Ivan Boothe Date: Mon, 25 Oct 2021 19:40:08 -0700 Subject: [PATCH] Adding HTML entity when it exists Signed-off-by: Ivan Boothe --- main.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 02021ce..28dbb0c 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,9 @@ import sys import codecs from os.path import join +import subprocess # for pip autoinstallation +import sys # for pip autoinstallation + from ulauncher.search.SortedList import SortedList from ulauncher.api.client.Extension import Extension from ulauncher.api.client.EventListener import EventListener @@ -25,6 +28,16 @@ ICON_TEMPLATE = """ """ +# For pip autoinstallation +def ensure_import(package): + try: + return __import__(package) + except ImportError: + subprocess.call([sys.executable, "-m", "pip", "install", "--user", package]) + return __import__(package) + +# For HTML entity conversion +htmlentities = ensure_import("htmlentities") class UnicodeChar: """ Container class for unicode characters @@ -71,11 +84,16 @@ class KeywordQueryEventListener(EventListener): result_list.extend(extension.character_list) for char in result_list: image_path = get_character_icon(char) + encoded = htmlentities.encode(char.character) + if "&" in encoded: + entity = " - " + encoded + else: + entity = "" items.append( ExtensionResultItem( icon=image_path, name=char.name.capitalize() + " - " + char.character, - description=char.block + " - " + char.code, + description=char.block + " - U+" + char.code + entity, on_enter=CopyToClipboardAction(char.character), ) )