markdown2模块如何从Python脚本中转换markdown文件?

2024-06-25 05:51:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是markdown2模块(可以在这里找到:https://github.com/trentm/python-markdown2),这个模块很棒,但是缺少文档。在

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

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

有人能告诉我怎么做吗?在


Tags: 模块文件方法代码from文档httpsgithub
1条回答
网友
1楼 · 发布于 2024-06-25 05:51:18

NVM,我得到了答案(而不是来自上面提到的存储库)。下面是一个简单的Python二行程序:

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

相关问题 更多 >