import re
with open('src/lib.rs') as f:
doc = f.read()
doc = re.sub(r'^/\*!\n(.*)\*/.*$', r'\1', doc, flags=re.DOTALL)
doc = re.sub(r'\n\n```\n', r'\n\n```rust\n', doc)
doc = re.sub(r'\[(`[^`]*`)]\[[^]]*\]', r'\1', doc)
doc = re.sub(r'\[(`[^`]*`)](?!\()', r'\1', doc)
doc = re.sub(r'^(#+)', r'#\1', doc, flags=re.M)
doc = """# genrc
[](https://crates.io/crates/genrc)

""" + doc + """
## License
genrc is licensed under either the MIT or Apache 2.0 license, whichever you
prefer.
"""
with open('README.md', 'w', newline='\n') as f:
print(doc, end='', file=f)