Skip to content

Instantly share code, notes, and snippets.

@andburn
Created February 24, 2017 11:03
Show Gist options
  • Save andburn/127eea90a0ee2f24ba50ebb05b920b04 to your computer and use it in GitHub Desktop.
Save andburn/127eea90a0ee2f24ba50ebb05b920b04 to your computer and use it in GitHub Desktop.
Parse IcoMoon font reference file to C# unicode strings
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