convert_to_markdown.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:ThinkingInPython 作者: BruceEckel 项目源码 文件源码
def main():
    source_dir = Path.cwd().parent / "src"
    temp_dir = Path.cwd().parent / "temp"
    dest_dir = Path.cwd().parent / "Markdown"

    def source_file(f): return source_dir / (f + ".rst")

    def pre_converted(f): return temp_dir / (f + ".rst")

    def converted(f): return temp_dir / (f + ".md")

    def destination(f, n): return dest_dir / ("%02d_" % n + f + ".md")
    assert all([source_file(f).exists() for f in source_order])
    all_files = [
        (source_file(f), pre_converted(f), converted(f), destination(f, n), n)
        for n, f in enumerate(source_order)
    ]

    create_clean_dir(temp_dir)
    create_clean_dir(dest_dir)
    for rst, pre, conv, md, n in all_files:
        print(f"{rst.name} -> {md.name}:")
        pre_convert(rst, pre)
        os.system(f"pandoc {pre} -o {conv}")
        post_convert(conv, md)
        if n > -1:
            os.system(f"subl {md}")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号