smurf.py 文件源码

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

项目:smurf 作者: oxalorg 项目源码 文件源码
def get_markdown():
    """
    Find and set a valid markdown parser
    Checks for one of these parsers:
        - pandoc
        - markdown2
    """
    markdown = None
    if shutil.which('pandoc'):
        markdown = lambda x: subprocess.run(
            ["pandoc", "-f", "markdown", "-t", "html"],
            input=x.encode("utf-8"),
            stdout=subprocess.PIPE).stdout.decode("utf-8")
    else:
        try:
            import markdown2
            _md_extras = [
                "code-friendly",
                "fenced-code-blocks",
                "footnotes",
                "header-ids",
            ]
            markdown = markdown2.Markdown(extras=_md_extras).convert
        except ImportError:
            pass

    if markdown is None:
        print("No markdown parser found. Will serve as plain text.")
    return markdown
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号