comrak 0.1.0

A 100% CommonMark-compatible GitHub Flavored Markdown parser and formatter
Documentation
# Creates data structures for binary lookup table of entities,
# using python's html5 entity data.
# Usage: python3 tools/make_entity_data_rs.py > src/entity_data.rs

def rust_hex(e):
    return "\\u{{{}}}".format(hex(ord(e))[2:])

import html

entities5 = html.entities.html5

# remove keys without semicolons.  For some reason the list
# has duplicates of a few things, like auml, one with and one
# without a semicolon.
entities = list(sorted([(k[:-1], entities5[k]) for k in entities5.keys() if k[-1] == ';']))

# Print out the header:
print("""// Autogenerated by script/make_entity_data.py

pub const MIN_LENGTH: usize = {};
pub const MAX_LENGTH: usize = {};
pub static ENTITIES: [(&'static str, &'static str); {}] =
    [""".format(
    min(map(lambda e: len(e[0]), entities)),
    max(map(lambda e: len(e[0]), entities)),
    len(entities)), end='')

for (i, (ent, bs)) in enumerate(entities):
    if i > 0:
        print('     ', end='')
    print('("{}", "{}")'.format(ent, ''.join(map(rust_hex, bs))), end='')
    if i < len(entities) - 1:
        print(',')

print("];")