I want to Convert my readme markdown to a .html file. The html file must contain a bootstrap css header. Any ideas?
Here is a solution with Error handling and variable inputs + Bootsrap 3 integration.
#! How to use: python3 md2html.py input.md output.html
import markdown
import sys
md_in_file = sys.argv[1]
html_out_file = sys.argv[2]
bootstrap_header = '<title>PPPT2HTML</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>'
try:
with open(md_in_file, 'r') as f:
text = f.read()
html = markdown.markdown(text)
print("✔️ MarkDown file found")
with open(html_out_file, 'w') as f:
f.write(bootstrap_header + html)
print("✔️ HTML file created")
except NameError:
print("❌ ERR0R: File not found")
except:
print("❌ ERR0R: general ERR0R")
USE:
python3 md2html.py input.md output.html