利用Python将markdown文档转为html文档
v1.0
作者:FZK
元素简单的md文件
Python中自带有一个markdown库,你可以直接这样使用
md_file = open("file.md","r",encoding='utf-8')
txt = md_file.read()
html = markdown.Markdown(txt)
较为复杂的md文件
由于我们需要转化的md文件比较复杂,存在表格、MathJax公式(latex中所用的公式)等复杂元素的时候,这种方式就不能完全转化。需要使用另一个py库:pip install python-markdown-math
具体代码如下:
import markdown
from mdx_math import MathExtension
html_head_file = open("html_head.txt","r",encoding='utf-8')
html_head = html_head_file.read()
html_head_file.close()
html_tail = "\n