使用 bootstrap 3 将 markdown 转换为自述文件

Convert markdown to readme with bootsrap 3

我想将我的自述文件 markdown 转换为 .html 文件。 html 文件必须包含 bootstrap css header。有什么想法吗?

这是一个错误处理和变量输入 + Bootstrap 3 集成的解决方案。

#! 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")

使用:

python3 md2html.py input.md output.html