Co-authored-by: Dalong <39682259+eedalong@users.noreply.github.com>
This commit is contained in:
Cheng Lai
2022-03-20 10:12:27 +08:00
committed by GitHub
parent 8fb5ff1b16
commit aefdd40ee6
4 changed files with 19 additions and 359 deletions

View File

@@ -9,27 +9,33 @@ import os
root_path = "./"
html_root_path = "_build/html/"
def get_html_list():
index_html_path = os.path.join(root_path,html_root_path ,"index.html")
index_html_path = os.path.join(root_path, html_root_path, "index.html")
index_soup = BeautifulSoup(open(index_html_path))
content_list = index_soup.find(name="div", attrs={"class":"globaltoc"}).\
content_list = index_soup.find(name="div", attrs={"class": "globaltoc"}). \
find_all(name="a", attrs={"class": "reference internal"})
html_list = [os.path.join(html_root_path,content_name["href"]) for content_name in content_list]
html_list = [os.path.join(html_root_path, content_name["href"]) for content_name in content_list]
return html_list
def format_table():
html_list = get_html_list()
for html_file in html_list:
soup = BeautifulSoup(open(html_file))
all_tables = soup.find_all(name="table", attrs={"class":"docutils align-default"})
for table in all_tables:
table["style"] = "margin-left:auto;margin-right:auto;margin-top:10px;margin-bottom:20px;"
try:
soup = BeautifulSoup(open(html_file))
all_tables = soup.find_all(name="table", attrs={"class": "docutils align-default"})
for table in all_tables:
table["style"] = "margin-left:auto;margin-right:auto;margin-top:10px;margin-bottom:20px;"
if len(all_tables):
write_out_file = open(html_file, mode="w")
write_out_file.write(soup.prettify())
write_out_file.close()
except:
pass
if len(all_tables):
write_out_file = open(html_file, mode="w")
write_out_file.write(soup.prettify())
write_out_file.close()
if __name__ == "__main__":
format_table()