content.gen.tidy.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from bs4 import BeautifulSoup
  4. import pypandoc
  5. import sys, os, shutil
  6. def main():
  7. # create main html dom from template
  8. template_f = open("template.html", "r")
  9. template_html = template_f.read()
  10. template_dom = BeautifulSoup(template_html, 'html.parser')
  11. pdoc_args = ['--mathjax',
  12. '--smart']
  13. pdoc_filters = []
  14. output = pypandoc.convert_file("log.OSP",
  15. to='html5',
  16. format='markdown+header_attributes+link_attributes+bracketed_spans',
  17. extra_args=pdoc_args,
  18. filters=pdoc_filters)
  19. # outputfile=out_f)
  20. # print("output :\n"+output)
  21. output_dom = BeautifulSoup(output, 'html.parser')
  22. log = template_dom.find('div', {'class':'log'})
  23. log.append(output_dom)
  24. # create main html file from filled template html dom
  25. book_html_f = os.path.join('final.html')
  26. with open(book_html_f, 'w') as fp:
  27. fp.write(template_dom.prettify(formatter=None))
  28. if __name__ == "__main__":
  29. main()