Skip to main content

Very lightweight CFFI-based Python bindings to cmark library (CommonMark implementation in C).

Project description

https://travis-ci.org/PavloKapyshin/paka.cmark.svg?branch=master

paka.cmark is a Python library that wraps subset of cmark C library (that is one of reference implementations of CommonMark).

Features

  • Python 2.7 and 3.6 are supported

  • PyPy (Python 2.7) 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paka.cmark-2.3.0.tar.gz (106.2 kB view details)

Uploaded Source

File details

Details for the file paka.cmark-2.3.0.tar.gz.

File metadata

  • Download URL: paka.cmark-2.3.0.tar.gz
  • Upload date:
  • Size: 106.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.9

File hashes

Hashes for paka.cmark-2.3.0.tar.gz
Algorithm Hash digest
SHA256 22933e26531516769dc1e26195ca3cb4a23b6093da052725bc543024f049a322
MD5 8bc02b3e62af6d712a6a5d0d0552de9a
BLAKE2b-256 90433c3d6b7f0d2f83e0bd412a6f1c9b2fbacc092be954dda0d98eba1688d210

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page