V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
lepture
V2EX  ›  Python

各种 Markdown Parsers

  •  
  •   lepture ·
    lepture · 2014-03-19 19:50:49 +08:00 · 4466 次点击
    这是一个创建于 3662 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这是我写的一篇介绍 Python 里的 Markdown Parser 的文章:

    http://lepture.com/en/2014/markdown-parsers-in-python

    列举了

    * Misaka: A python binding for Sundown. (CPython required)
    * Hoedown: A python binding for Hoedown, successor of Misaka.
    * Discount: A python binding for Discount. (CPython required)
    * cMarkdown: Markdown for Python, accelerated by C. (CPython required)
    * Markdown: A pure markdown parser, the very first implementation.
    * Markdown2: Another pure markdown parser.
    * Mistune: The fastest markdown parser in pure Python.

    其中要说明的是许多人被 Markdown2 骗了,这个号称 fast 的解析器是效率最低的。详情见我做的 benchmark: https://github.com/lepture/mistune/issues/1
    12 条回复    2014-07-03 15:44:50 +08:00
    yinian1992
        1
    yinian1992  
       2014-03-20 08:36:58 +08:00 via Android
    但是 markdown2 的 readme 上也写了 “That was a while ago though, so you shouldn't discount Python-markdown from your consideration.”
    我觉得 markdown2 最大的问题是扩展起来太 dirty 了。
    zqqf16
        2
    zqqf16  
       2014-03-20 08:39:34 +08:00
    俺当年也被骗了,直到后来发现Markdown2对多行代码的支持不太好才放弃了~
    soli
        3
    soli  
       2014-03-20 09:08:54 +08:00
    好像 Mou 用的就是 Discount 。 Discount 真的那么不堪么?
    housne
        4
    housne  
       2014-03-20 09:26:02 +08:00
    If you are on a Windows, may god helps you. I don't care it a shit. lol
    lepture
        5
    lepture  
    OP
       2014-03-20 09:48:59 +08:00
    @yinian1992 我目前最喜欢的是 renderer 方案。因为语法几乎不用扩展,需要修改的一般是渲染效果。
    lepture
        6
    lepture  
    OP
       2014-03-20 09:49:56 +08:00
    @soli 我文章里说的是 Discount 的 Python Binding。因为这货压根就没法安装。
    soli
        7
    soli  
       2014-03-20 09:54:46 +08:00
    @lepture 期待一个所有语言的 Markdown parser 评测。
    lepture
        8
    lepture  
    OP
       2014-03-20 10:11:14 +08:00
    @soli 没有必要测所有语言,如果是测速度的话,只用测 C 就好了。
    yinian1992
        9
    yinian1992  
       2014-03-20 12:26:16 +08:00
    @lepture 最后发现,要不还是用 rst 吧,md 感觉像是半成品。
    lepture
        10
    lepture  
    OP
       2014-03-20 15:04:05 +08:00
    @yinian1992 目的不同

    > Markdown is a text-to-HTML conversion tool for web writers.

    它本来就不是为写文档设计的。

    http://lepture.com/zh/2013/typography-and-markdown
    walnutist
        11
    walnutist  
       2014-03-25 11:57:39 +08:00
    我最近折腾了一遍Markdown Parser,Python的这些Parser后来全被我毙了,最终决定使用这个
    https://github.com/evilstreak/markdown-js

    我在选型过程中主要考虑的因素是:
    1、高度可扩展。我要的不是单纯标准的Markdown,更像是Markdown-like。Markdown本身还是太过geek。
    2、前后端Parser功能上一致
    3、可以轻松toHTML, toText, toPDF....
    4、Parser应该相对成熟和稳定

    最终让我下定决心选择markdown-js的因素,也是因为discourse用了这个框架,在discourse的代码中有很好的扩展实例。

    解析速度不是我关心的重点,因为我的app架构是后端node.js透过rest提供markdown-to-html服务,并直接在redis中缓存结果。
    lepture
        12
    lepture  
    OP
       2014-07-03 15:44:50 +08:00
    @walnutist javascript 的明顯是 https://github.com/chjj/marked 要好很多。不僅僅是最快的,也是最容易讀懂代碼的,也是最容易擴展的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3601 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:00 · PVG 13:00 · LAX 22:00 · JFK 01:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.