paka.cmark is a Python library that wraps subset of cmark C library (that is one of reference implementations of CommonMark).
Features
Python 3.6+ is supported
PyPy is supported, as wrapping is made with CFFI
no need to install libcmark, it is bundled with paka.cmark (and sources of the former are regularly updated according to upstream)
supported output: HTML, XML, CommonMark, man, LaTeX
supported options: CMARK_OPT_UNSAFE, CMARK_OPT_NOBREAKS, CMARK_OPT_HARDBREAKS, CMARK_OPT_SOURCEPOS, CMARK_OPT_SMART
unlike libcmark—underlying C library—paka.cmark uses CMARK_OPT_NOBREAKS by default (breaks argument allows to control line break rendering)
safe HTML output is on by default (like in libcmark)
Examples
>>> from paka import cmark
Render with CMARK_OPT_DEFAULT | CMARK_OPT_NOBREAKS:
>>> print(cmark.to_html(u"<p>nope</p>"))
<!-- raw HTML omitted -->
Render with CMARK_OPT_DEFAULT | CMARK_OPT_NOBREAKS | CMARK_OPT_UNSAFE:
>>> print(cmark.to_html(u"Hello,\n*World*!", safe=False))
<p>Hello, <em>World</em>!</p>
Render with CMARK_OPT_DEFAULT:
>>> print(cmark.to_html(u"Hello,\n*World*!", breaks=True))
<p>Hello,
<em>World</em>!</p>
Render with CMARK_OPT_DEFAULT | CMARK_OPT_HARDBREAKS:
>>> print(cmark.to_html(u"Hello,\n*World*!", breaks="hard"))
<p>Hello,<br />
<em>World</em>!</p>
Render CommonMark with CMARK_OPT_DEFAULT | CMARK_OPT_NOBREAKS:
>>> print(cmark.to_commonmark(u"_Hello_"))
*Hello*
Installation
Library is available on PyPI, you can use pip for installation:
$ pip install paka.cmark
Getting documentation
Build HTML docs:
$ tox -e docs
View built docs:
$ sensible-browser .tox/docs/tmp/docs_html/index.html
Running tests
$ tox
Getting coverage
Collect info:
$ tox -e coverage
View HTML report:
$ sensible-browser .tox/coverage/tmp/cov_html/index.html
Checking code style
Run code checkers:
$ tox -e checks
Release files for paka.cmark 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| paka_cmark-3.0.0.tar.gz | 130.0 kB | Details |
Release files / paka_cmark-3.0.0.tar.gz
| Download URL | paka_cmark-3.0.0.tar.gz |
|---|---|
| Size | 130.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3640b12698b07a7f422750c909ac32b76e43aaaff22a64ecde4f22c8ff8ba93
|
|
BLAKE2b-256 checksum How to use checksums |
31694505fbe75f1d446a0b5d924eb4203bedecb17ed8ac2d202333907b2e631f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|