2023-03-29 08:53:20 +05:30
|
|
|
import pathlib
|
|
|
|
|
|
|
|
SPHINX_ROOT_DIR = pathlib.Path(".")
|
2025-06-09 18:50:31 +09:00
|
|
|
SPHINX_BUILD_DIR = SPHINX_ROOT_DIR / pathlib.Path("_build/markdown/apidocs")
|
2023-03-29 08:53:20 +05:30
|
|
|
DOCS_OUTPUT_DIR = pathlib.Path("../docs/python-sdk")
|
|
|
|
|
|
|
|
|
2025-06-09 18:50:31 +09:00
|
|
|
def main():
|
|
|
|
DOCS_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
2023-03-29 08:53:20 +05:30
|
|
|
|
2025-06-09 18:50:31 +09:00
|
|
|
for doc in SPHINX_BUILD_DIR.glob("**/*.md"):
|
|
|
|
outfile = DOCS_OUTPUT_DIR / doc.relative_to(SPHINX_BUILD_DIR)
|
|
|
|
outfile.parent.mkdir(parents=True, exist_ok=True)
|
2023-03-29 08:53:20 +05:30
|
|
|
|
2025-06-09 18:50:31 +09:00
|
|
|
with open(doc, "r") as f:
|
|
|
|
content = f.read()
|
2023-03-29 08:53:20 +05:30
|
|
|
|
2025-06-09 18:50:31 +09:00
|
|
|
# Replace dangerous characters
|
|
|
|
replacements = [
|
|
|
|
("<function ", "<\\function "),
|
|
|
|
("<id>", "<\\id>"),
|
|
|
|
("<type>", "<\\type>"),
|
|
|
|
("<id1>", "<\\id1>"),
|
|
|
|
("<id2>", "<\\id2>"),
|
|
|
|
("MDXContent.isMDXComponent = true", ""),
|
|
|
|
]
|
|
|
|
for old, new in replacements:
|
|
|
|
content = content.replace(old, new)
|
2023-03-29 08:53:20 +05:30
|
|
|
|
2025-06-09 18:50:31 +09:00
|
|
|
# Wrap the entire content with div (top and bottom)
|
|
|
|
final_content = f"<div className=\"python-sdk\">\n\n{content.strip()}\n\n</div>\n"
|
2023-03-29 08:53:20 +05:30
|
|
|
|
2025-06-09 18:50:31 +09:00
|
|
|
with open(outfile, "w") as f:
|
|
|
|
f.write(final_content)
|
2023-03-29 08:53:20 +05:30
|
|
|
|
2025-06-09 18:50:31 +09:00
|
|
|
print(f"✅ Generated {outfile}")
|
2023-03-29 08:53:20 +05:30
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|