Last active
May 19, 2016 20:19
-
-
Save jsbueno/60cda75cb784aa75a554d542820c5726 to your computer and use it in GitHub Desktop.
bolderificator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
from urllib.request import urlopen | |
import re | |
import unicodedata | |
def fetch(): | |
data = urlopen("https://www.w3.org/TR/MathML2/double-struck.html").read() | |
dcontent = re.findall(r"<td.*?>\s*?(.*?)</td", data.decode("utf-8")) | |
return dcontent | |
def get_double_chars(dcontent): | |
results = {} | |
for i, data in enumerate(dcontent): | |
if not data.startswith('MATH'): continue | |
if "DIGIT" in data: | |
name = data[data.index("DIGIT"):] | |
key = unicodedata.lookup(name) | |
elif "SMALL" in data: | |
key = data.split()[-1].lower() | |
else: | |
key = data.split()[-1] | |
results[key] = r"\U{:08x}".format(int(dcontent[i - 3], 16)).encode("latin1").decode("unicode_escape") | |
return results | |
def bolderificator(text, map_): | |
return "".join(map_.get(letter, letter) for letter in unicodedata.normalize("NFD", text)) | |
grifa = lambda texto: "".join(letra + "\u035f" for letra in texto ) | |
grifa2 = lambda texto: "".join(letra + "\u035e\u035f" for letra in texto ) | |
# doublechars = get_double_chars(fetch()) | |
# print(repr(doublechars)) | |
if __name__ == "__main__": | |
dcontent = fetch() | |
map_ = get_double_chars(dcontent) | |
query = "blah" | |
while query: | |
query = input("String to make bold: ") | |
print(bolderificator(query, map_)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import chain | |
bolder = lambda text: "".join(chr(0x1d400 + ord(letter.upper()) - 0x41 + (26 if letter.islower() else 991 if letter.isdigit() else 0)) if letter.isalnum() and ord(letter) < 128 else letter for letter in chain (*(unicodedata.normalize("NFD", letter2) for letter2 in text) )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
underline = lambda text: "".join(letter + "\u035f" for letter in text ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
About "underline" - all characters on the 0x0300 - 0x36f range are "combinable" - and you can use more than one to display a single glyph.