LDoc: add README
This commit is contained in:
parent
1a85acc4c9
commit
9e926bdc54
@ -31,6 +31,7 @@ format = "markdown"
|
||||
boilerplate = false
|
||||
not_luadoc = true
|
||||
favicon = "https://www.minetest.net/media/icon.svg"
|
||||
readme = ".ldoc/README.md"
|
||||
|
||||
file = {
|
||||
"api.lua",
|
||||
|
@ -10,5 +10,14 @@ cd "${d_root}"
|
||||
# clean old files
|
||||
rm -rf "${d_export}"
|
||||
|
||||
rm -f "${d_ldoc}/README.md"
|
||||
|
||||
./.ldoc/parse_readme.py
|
||||
|
||||
# create new files
|
||||
ldoc --UNSAFE_NO_SANDBOX -c "${f_config}" -d "${d_export}" "${d_root}"
|
||||
|
||||
# cleanup
|
||||
rm -f "${d_ldoc}/README.md"
|
||||
|
||||
cp "${d_root}/screenshot.png" "${d_export}"
|
||||
|
84
.ldoc/parse_readme.py
Executable file
84
.ldoc/parse_readme.py
Executable file
@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys, os, codecs, errno, shutil
|
||||
|
||||
|
||||
f_script = os.path.realpath(__file__)
|
||||
d_ldoc = os.path.dirname(f_script)
|
||||
d_root = os.path.dirname(d_ldoc)
|
||||
|
||||
f_readme_src = os.path.join(d_root, "README.md")
|
||||
f_readme_tgt = os.path.join(d_ldoc, "README.md")
|
||||
|
||||
if not os.path.isfile(f_readme_src):
|
||||
print("ERROR: source README.md does not exists")
|
||||
sys.exit(errno.ENOENT)
|
||||
|
||||
buffer = codecs.open(f_readme_src, "r", "utf-8")
|
||||
if not buffer:
|
||||
print("ERROR: could not open source README.md for reading")
|
||||
sys.exit(1)
|
||||
|
||||
r_data = buffer.read()
|
||||
buffer.close()
|
||||
|
||||
r_data = r_data.replace("\r\n", "\n").replace("\r", "\n")
|
||||
r_lines = r_data.split("\n")
|
||||
r_lines_pre = []
|
||||
r_lines_post = []
|
||||
table = []
|
||||
|
||||
mid = False
|
||||
post = False
|
||||
for line in r_lines:
|
||||
if line.startswith("###"):
|
||||
line = line.rstrip(":")
|
||||
|
||||
'''
|
||||
if line.count("_") > 1:
|
||||
line = line.replace("_", "\\_")
|
||||
'''
|
||||
|
||||
if "src=\"screenshot.png\"" in line:
|
||||
line = line.replace("screenshot.png", "../screenshot.png")
|
||||
|
||||
if line.startswith("|"):
|
||||
mid = True
|
||||
|
||||
if mid:
|
||||
if line.startswith("|"):
|
||||
if line.startswith("| Filename"):
|
||||
line = "{}\n".format(line.lstrip("| ").rstrip(" |")).replace("_", "\\_")
|
||||
else:
|
||||
line = "- {}".format(line.lstrip("|").rstrip(" |"))
|
||||
|
||||
while " " in line:
|
||||
line = line.replace(" ", " ")
|
||||
|
||||
if line.replace("-", "").replace("|", "").strip() == "":
|
||||
continue
|
||||
|
||||
if line.startswith("#####"):
|
||||
line = "<br/>\n{}".format(line)
|
||||
|
||||
table.append(line)
|
||||
|
||||
if line == "### Usage:":
|
||||
post = True
|
||||
mid = False
|
||||
continue
|
||||
|
||||
if post:
|
||||
r_lines_post.append(line)
|
||||
elif not mid:
|
||||
r_lines_pre.append(line)
|
||||
|
||||
buffer = codecs.open(f_readme_tgt, "w", "utf-8")
|
||||
if not buffer:
|
||||
print("ERROR: could not open target README.md for writing")
|
||||
sys.exit(1)
|
||||
|
||||
buffer.write("{}\n\n{}\n\n{}".format("\n".join(r_lines_pre), "\n".join(table), "\n".join(r_lines_post)))
|
||||
buffer.close()
|
||||
|
||||
print("\nDone!")
|
Loading…
x
Reference in New Issue
Block a user