1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- from bs4 import BeautifulSoup
- import pypandoc
- import sys, os, shutil
- def main():
- # create main html dom from template
- template_f = open("template.html", "r")
- template_html = template_f.read()
- template_dom = BeautifulSoup(template_html, 'html.parser')
- pdoc_args = ['--mathjax',
- '--smart']
- pdoc_filters = []
- output = pypandoc.convert_file("log.OSP",
- to='html5',
- format='markdown+header_attributes+link_attributes+bracketed_spans',
- extra_args=pdoc_args,
- filters=pdoc_filters)
- # outputfile=out_f)
- # print("output :\n"+output)
- output_dom = BeautifulSoup(output, 'html.parser')
- log = template_dom.find('div', {'class':'log'})
- log.append(output_dom)
- # create main html file from filled template html dom
- book_html_f = os.path.join('final.html')
- with open(book_html_f, 'w') as fp:
- fp.write(template_dom.prettify(formatter=None))
- if __name__ == "__main__":
- main()
|