python中使用和修复markdown


Python 中使用和修复Markdown

要在Python中格式化Markdown文本 第三方库来处理Markdown语法

markdown转html

markdown

  • 安装markdown

    pip install markdown
  • Markdown 文本转 html

    from markdown import Markdown
    
    title = "My Markdown Document"
    content = "This is a **bold** sentence."
    md_text = f"# {title}\n\n{content}"
    
    md = Markdown()
    
    html = md.convert(md_text)
    print(html)
    
    # 输出
    # <h1>My Markdown Document</h1>
    # <p>This is a <strong>bold</strong> sentence.</p>
    

mistune

  • 安装mistune

    pip install mistune
  • Markdown 文本转 html

    import mistune
    
    title = "My Markdown Document"
    content = "This is a **bold** sentence."
    md_text = f"# {title}\n\n{content}"
    
    html = mistune.markdown(md_text)
    
    print(html)
    
    # 输出
    # <h1>My Markdown Document</h1>
    # <p>This is a <strong>bold</strong> sentence.</p>
`adawd `

adawd

–dawdaw–

–awd–

—awdaw

***

文章作者: Wanheng
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Wanheng !
评论
  目录