Debian Codegraph @

README.rst

raw
1 commonmark.py
2 =============
3
4 |No Maintenance Intended|
5
6 **Warning:** commonmark.py is now deprecated. We recommend using `markdown-it-py`_
7 for a commonmark parser going forward. See `this issue`_ for background
8 and discussion.
9
10 --
11
12 .. _markdown-it-py: https://github.com/executablebooks/markdown-it-py
13 .. _this issue: https://github.com/readthedocs/commonmark.py/issues/308
14
15 .. |No Maintenance Intended| image:: http://unmaintained.tech/badge.svg
16 :target: http://unmaintained.tech/
17
18 commonmark.py is a pure Python port of `jgm <https://github.com/jgm>`__'s
19 `commonmark.js <https://github.com/jgm/commonmark.js>`__, a
20 Markdown parser and renderer for the
21 `CommonMark <http://commonmark.org>`__ specification, using only native
22 modules. Once both this project and the CommonMark specification are
23 stable we will release the first ``1.0`` version and attempt to keep up
24 to date with changes in ``commonmark.js``.
25
26 commonmark.py is tested against the CommonMark spec with Python versions
27 2.7, 3.5, 3.6, 3.7, and 3.8.
28
29 **Current version:** 0.9.2
30
31 |Pypi Link| |Build Status| |Doc Link|
32
33 Installation
34 ------------
35
36 ::
37
38 $ pip install commonmark
39
40 Usage
41 -----
42
43 ::
44
45 >>> import commonmark
46 >>> commonmark.commonmark('*hello!*')
47 '<p><em>hello!</em></p>\n'
48
49 Or, without the syntactic sugar:
50
51 .. code:: python
52
53 import commonmark
54 parser = commonmark.Parser()
55 ast = parser.parse("Hello *World*")
56
57 renderer = commonmark.HtmlRenderer()
58 html = renderer.render(ast)
59 print(html) # <p>Hello <em>World</em><p/>
60
61 # inspecting the abstract syntax tree
62 json = commonmark.dumpJSON(ast)
63 commonmark.dumpAST(ast) # pretty print generated AST structure
64
65 There is also a CLI:
66
67 ::
68
69 $ cmark README.md -o README.html
70 $ cmark README.md -o README.json -aj # output AST as JSON
71 $ cmark README.md -a # pretty print generated AST structure
72 $ cmark -h
73 usage: cmark [-h] [-o [O]] [-a] [-aj] [infile]
74
75 Process Markdown according to the CommonMark specification.
76
77 positional arguments:
78 infile Input Markdown file to parse, defaults to stdin
79
80 optional arguments:
81 -h, --help show this help message and exit
82 -o [O] Output HTML/JSON file, defaults to stdout
83 -a Print formatted AST
84 -aj Output JSON AST
85
86
87 Contributing
88 ------------
89
90 If you would like to offer suggestions/optimizations/bugfixes through
91 pull requests please do! Also if you find an error in the
92 parser/renderer that isn't caught by the current test suite please open
93 a new issue and I would also suggest you send the
94 `commonmark.js <https://github.com/jgm/commonmark.js>`__ project
95 a pull request adding your test to the existing test suite.
96
97 Tests
98 -----
99
100 To work on commonmark.py, you will need to be able to run the test suite to
101 make sure your changes don't break anything. To run the tests, you can do
102 something like this:
103
104 ::
105
106 $ pyvenv venv
107 $ ./venv/bin/python setup.py develop test
108
109 The tests script, ``commonmark/tests/run_spec_tests.py``, is pretty much a devtool. As
110 well as running all the tests embedded in ``spec.txt`` it also allows you
111 to run specific tests using the ``-t`` argument, provide information
112 about passed tests with ``-p``, percentage passed by category of test
113 with ``-s``, and enter markdown interactively with ``-i`` (In
114 interactive mode end a block by inputting a line with just ``end``, to
115 quit do the same but with ``quit``). ``-d`` can be used to print call
116 tracing.
117
118 ::
119
120 $ ./venv/bin/python commonmark/tests/run_spec_tests.py -h
121 usage: run_spec_tests.py [-h] [-t T] [-p] [-f] [-i] [-d] [-np] [-s]
122
123 script to run the CommonMark specification tests against the commonmark.py
124 parser.
125
126 optional arguments:
127 -h, --help show this help message and exit
128 -t T Single test to run or comma separated list of tests (-t 10 or -t 10,11,12,13)
129 -p Print passed test information
130 -f Print failed tests (during -np...)
131 -i Interactive Markdown input mode
132 -d Debug, trace calls
133 -np Only print section header, tick, or cross
134 -s Print percent of tests passed by category
135
136 Authors
137 -------
138
139 - `Bibek Kafle <https://github.com/kafle>`__
140 - `Roland Shoemaker <https://github.com/rolandshoemaker>`__
141
142 .. |Pypi Link| image:: https://img.shields.io/pypi/v/commonmark.svg
143 :target: https://pypi.org/project/commonmark/
144
145 .. |Build Status| image:: https://travis-ci.org/rtfd/commonmark.py.svg?branch=master
146 :target: https://travis-ci.org/rtfd/commonmark.py
147
148 .. |Doc Link| image:: https://readthedocs.org/projects/commonmarkpy/badge/?version=latest
149 :target: https://commonmarkpy.readthedocs.io/en/latest/?badge=latest
150 :alt: Documentation Status