Created
February 24, 2017 11:03
-
-
Save andburn/127eea90a0ee2f24ba50ebb05b920b04 to your computer and use it in GitHub Desktop.
Parse IcoMoon font reference file to C# unicode strings
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 lxml import html | |
with open("reference.html", "r") as f: | |
data = f.read() | |
tree = html.fromstring(data) | |
divs = tree.xpath("//div[contains(@class, 'glyph')]") | |
defs = [] | |
for d in divs: | |
hex_code = d.xpath("./fieldset/input[1]/@value")[0] | |
names = d.xpath("./div[2]/input/@value")[0] | |
name = names.split(",")[0].replace("-", " ").title().replace(" ", "") | |
defs.append('public const string {} = "\\u{}";'.format(name, hex_code)) | |
with open("references.cs", "w") as f: | |
f.write("\n".join(defs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment