python转换markdown为html表格高亮

2024-02-26 15:02 python转换markdown为html表格高亮已关闭评论

1. 安装markdwon

安装markdwon,执行命令

pip install markdown

2. 转换为html

读取.md文件(注意中文),指定encoding编码为UTF-8

with open(file_path, 'r', encoding='UTF-8') as file:
    text = file.read()
    html = markdown.markdown(text)
    print(html)
    return html

3. 表格高亮

添加extensions=['tables']

with open(file_path, 'r', encoding='UTF-8') as file:
    text = file.read()
    html = markdown.markdown(text,extensions=['tables'])
    print(html)
    return html

你可能感兴趣的文章

来源:每日教程, 每日一例,深入学习实用技术教程,关注公众号TeachCourse
转载请注明出处: https://teachcourse.cn/3050.html ,谢谢支持!

资源分享

分类:python 标签:,
MCP 协议原理与自定义服务器开发实战:从零搭建 AI 工具调用网关 MCP 协议原理与自定义服务器开
Python框架Flask开发接口详细介绍 Python框架Flask开发接口详细介
Windows 10 C盘微信应用占据空间大小分析 Windows 10 C盘微信应用占据空
AI 代码生成供应链安全实战:Slopsquatting 依赖投毒与防御指南 AI 代码生成供应链安全实战:S

评论已关闭!