Skip to content

Instantly share code, notes, and snippets.

@jsbueno
Last active May 19, 2016 20:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbueno/60cda75cb784aa75a554d542820c5726 to your computer and use it in GitHub Desktop.
Save jsbueno/60cda75cb784aa75a554d542820c5726 to your computer and use it in GitHub Desktop.
bolderificator.py
#! /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_))
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) ))
underline = lambda text: "".join(letter + "\u035f" for letter in text )
@jsbueno
Copy link
Author

jsbueno commented May 13, 2016

About "underline" - all characters on the 0x0300 - 0x36f range are "combinable" - and you can use more than one to display a single glyph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment