You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB
Python

from glob import glob
import os
import subprocess
# https://devdocs.io/python~3.9/library/glob#glob.glob
files = glob("content/**", recursive=True)
print(files)
print("---------")
all_html = ""
for file in files:
#print(file)
if file.endswith(".md"):
print("===========")
file = file.replace(" ", "\ ")
print(file)
html_file = file.replace(".md", ".html")
pandoc_cmd = "pandoc -s -c style.css -f markdown -t html " + file + " -o " + html_file
os.system(pandoc_cmd)
print("standalone html files saved!")
pandoc2 = "pandoc -f markdown -t html " + file
html_data = subprocess.run(pandoc2, capture_output=True, text=True).stdout
print("This is the html data: ", html_data)
# and then collect all that content into a variable called "all_html"
# add this content to all_html
all_html = all_html + html_data
print("----------")
print(all_html)
template = f"""<!DOCTYPE html>
<html>
<head>
<script src="paged.js/paged.polyfill.js"></script>
<link href="paged.js/pagedjs.css" rel="stylesheet" type="text/css">
<link href="print.css" rel="stylesheet" type="text/css" media="print">
<meta charset="UTF-8">
</head>
<body>
{ all_html }
</body>
</html>
"""
output = open("booklet.html", "w")
output.write(template)
# Now open this page in the browser, remember: paged.js needs to be accessed through a webserver.
# To run a webserver locally, you can use:
# cd SI20/booklet/
# python3 -m http.server
# localhost:8000/booklet.html