Adding HTML entity when it exists
Signed-off-by: Ivan Boothe <ivan@rootwork.org>
This commit is contained in:
		
							parent
							
								
									67bf4bce73
								
							
						
					
					
						commit
						976055c5c7
					
				
					 1 changed files with 19 additions and 1 deletions
				
			
		
							
								
								
									
										20
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										20
									
								
								main.py
									
										
									
									
									
								
							| 
						 | 
					@ -3,6 +3,9 @@ import sys
 | 
				
			||||||
import codecs
 | 
					import codecs
 | 
				
			||||||
from os.path import join
 | 
					from os.path import join
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import subprocess # for pip autoinstallation
 | 
				
			||||||
 | 
					import sys # for pip autoinstallation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ulauncher.search.SortedList import SortedList
 | 
					from ulauncher.search.SortedList import SortedList
 | 
				
			||||||
from ulauncher.api.client.Extension import Extension
 | 
					from ulauncher.api.client.Extension import Extension
 | 
				
			||||||
from ulauncher.api.client.EventListener import EventListener
 | 
					from ulauncher.api.client.EventListener import EventListener
 | 
				
			||||||
| 
						 | 
					@ -25,6 +28,16 @@ ICON_TEMPLATE = """
 | 
				
			||||||
</svg>
 | 
					</svg>
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 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:
 | 
					class UnicodeChar:
 | 
				
			||||||
    """ Container class for unicode characters
 | 
					    """ Container class for unicode characters
 | 
				
			||||||
| 
						 | 
					@ -71,11 +84,16 @@ class KeywordQueryEventListener(EventListener):
 | 
				
			||||||
            result_list.extend(extension.character_list)
 | 
					            result_list.extend(extension.character_list)
 | 
				
			||||||
            for char in result_list:
 | 
					            for char in result_list:
 | 
				
			||||||
                image_path = get_character_icon(char)
 | 
					                image_path = get_character_icon(char)
 | 
				
			||||||
 | 
					                encoded = htmlentities.encode(char.character)
 | 
				
			||||||
 | 
					                if "&" in encoded:
 | 
				
			||||||
 | 
					                    entity = " - " + encoded
 | 
				
			||||||
 | 
					                else:
 | 
				
			||||||
 | 
					                    entity = ""
 | 
				
			||||||
                items.append(
 | 
					                items.append(
 | 
				
			||||||
                    ExtensionResultItem(
 | 
					                    ExtensionResultItem(
 | 
				
			||||||
                        icon=image_path,
 | 
					                        icon=image_path,
 | 
				
			||||||
                        name=char.name.capitalize() + " - " + char.character,
 | 
					                        name=char.name.capitalize() + " - " + char.character,
 | 
				
			||||||
                        description=char.block + " - " + char.code,
 | 
					                        description=char.block + " - U+" + char.code + entity,
 | 
				
			||||||
                        on_enter=CopyToClipboardAction(char.character),
 | 
					                        on_enter=CopyToClipboardAction(char.character),
 | 
				
			||||||
                    )
 | 
					                    )
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue