纯Python的Markdown解析器和渲染器:CommonMark-py

jopen 10年前

Pure Python port of CommonMark-py是 jgmstmd.js一个纯Python移植。一个CommonMark规范的Markdown解析器和渲染器,只使用了原生的模块。

import CommonMark  parser = CommonMark.DocParser()  renderer = CommonMark.HTMLRenderer()  ast = parser.parse("Hello *World*")  html = renderer.render(ast)  json = CommonMark.ASTtoJSON(ast)  CommonMark.dumpAST(ast) # pretty print generated AST structure  print(html) # <p>Hello <em>World</em><p/>    ----- or -----    rolands@kamaji:~$ cmark.py README.md -o README.html  rolands@kamaji:~$ cmark.py README.md -o README.json -aj # output AST as JSON  rolands@kamaji:~$ cmark.py README.md -a # pretty print generated AST structure  rolands@kamaji:~$ cmark.py -h  usage: cmark.py [-h] [-o [O]] [-a] [-aj] [infile]    Process Markdown according to the CommonMark specification.    positional arguments:    infile      Input Markdown file to parse, defaults to stdin    optional arguments:    -h, --help  show this help message and exit    -o [O]      Output HTML/JSON file, defaults to stdout    -a          Print formatted AST    -aj         Output JSON AST

项目主页:http://www.open-open.com/lib/view/home/1414740974919