in scripts/parse_sphinx.py [0:0]
def parse_sphinx(input_dir, output_dir):
for cur, _, files in os.walk(input_dir):
for fname in files:
if fname.endswith(".html"):
with open(os.path.join(cur, fname), "r") as f:
soup = BeautifulSoup(f.read(), "html.parser")
doc = soup.find("div", {"class": "document"})
wrapped_doc = doc.wrap(
soup.new_tag("div", **{"class": "sphinx wrapper"})
)
# add scripts that sphinx pages need
if fname == "search.html":
out = (
base_scripts
+ search_js_scripts
+ katex_scripts
+ str(wrapped_doc)
)
else:
out = base_scripts + katex_scripts + str(wrapped_doc)
output_path = os.path.join(output_dir, os.path.relpath(cur, input_dir))
os.makedirs(output_path, exist_ok=True)
with open(os.path.join(output_path, fname), "w") as fout:
fout.write(out)