把markdown文件转换为html文件

  • 使用pip install markdown模块
  • 只做到了分行;
  • 表格,-,和空格还没能无缝转换
  • 代码如下:
import os
import codecs
import markdown

def convert_markdown_to_html(markdown_file):
    with codecs.open(markdown_file,'r',encoding='utf-8') as file:
        markdown_text = file.read()
        html_text = markdown.markdown(markdown_text,extensions=['nl2br'])

    html_file = os.path.splitext(markdown_file)[0] + '.html'
    with codecs.open(html_file,'w',encoding='utf-8') as file:
        file.write(html_text)

markdown_file = ".//test.md"
convert_markdown_to_html(markdown_file)
posted @   不愿透露姓名的小村村  阅读(109)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示