【问题标题】:markdown2 module - how do I convert a a markdown file from within a Python script?markdown2 模块 - 如何从 Python 脚本中转换 markdown 文件?
【发布时间】:2018-11-17 03:31:59
【问题描述】:

我正在使用 markdown2 模块(可在此处找到:https://github.com/trentm/python-markdown2)该模块很棒,但缺少文档。

我尝试了一些简单的事情,比如使用 Python 脚本转换文件。然后我想用它来转换一批文件。但即使是第一部分也陷入了死胡同。我的代码:

from markdown2 import Markdown
markdowner = Markdown()
markdowner.convert("file.md", "file.htm")

谁能告诉我怎么做?

【问题讨论】:

标签: python markdown


【解决方案1】:

NVM,我得到了答案(而不是来自上面提到的存储库)。这是一个简单的 Pythonic 两行代码:

from markdown2 import Markdown
with open("file.htm", 'w') as output_file: output_file.write(Markdown().convert(open("file.md").read()))

【讨论】:

    猜你喜欢
    • 2021-05-23
    • 1970-01-01
    • 2015-02-19
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 2019-08-17
    • 1970-01-01
    相关资源
    最近更新 更多