evennia/docs/pylib/api_rst2md.py

33 lines
889 B
Python
Raw Normal View History

2021-10-21 21:04:14 +02:00
#!/usr/bin/python
"""
Remap autodoc API rst files to md files and wrap their contents.
"""
from glob import glob
from os import rename
2022-11-10 22:21:12 +01:00
from os.path import abspath, dirname
from os.path import join as pathjoin
2021-10-21 21:04:14 +02:00
def _rst2md(filename_rst):
2022-02-08 13:03:52 +01:00
with open(filename_rst, "r") as fil:
2021-10-21 21:04:14 +02:00
# read rst file, reformat and save
txt = fil.read()
2022-02-08 13:03:52 +01:00
with open(filename_rst, "w") as fil:
2021-10-21 21:04:14 +02:00
txt = "```{eval-rst}\n" + txt + "\n```"
fil.write(txt)
# rename .rst file to .md file
2022-02-08 13:03:52 +01:00
filename, _ = filename_rst.rsplit(".", 1)
2021-10-21 21:04:14 +02:00
filename_md = filename + ".md"
rename(filename_rst, filename_md)
if __name__ == "__main__":
apidir = pathjoin(dirname(dirname(abspath(__file__))), "source", "api")
for filename_rst in glob(pathjoin(apidir, "*.rst")):
_rst2md(filename_rst)
print(" Converted {apidir}/*.rst files to .md files".format(apidir=apidir))