#! /usr/bin/env python3
import panflute as pf

shorthands = {
    r'\um': r'$\mu \mathrm{m}$',
}


def handle_shorthand(elem, doc):
    if isinstance(elem, pf.Str):
        for shorthand, replacement in shorthands.items():
            parts = elem.text.split(shorthand)
            if len(parts) > 1:
                # build a new thinggy
                pass
            else:

            new = elem.text.replace(shorthand, replacement)
            if new != elem.text:
                print(new, elem.text)
    return elem


def main(doc=None):
    return pf.run_filter(handle_shorthand, doc=doc)


if __name__ == "__main__":
    main()
