Git Product home page Git Product logo

paka.cmark's Introduction

paka.cmark

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

paka.cmark's People

Contributors

jberkel avatar kapyshin avatar lowks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

paka.cmark's Issues

Implement other output formats

I need to perform some CommonMark cleaning from Python code and would like to parse and regenerate the markup with this libary.

This would require to add support for FORMAT_COMMONMARK (maybe others) to the code.
Happy to do this and submit a PR, but first wanted to check if that's something you would integrate (it kind of goes against the simple+lightweight tag line of the project).

Memory Leak

There seems to be a memory leak, running the following code will gradually eat up all of your RAM:

from paka import cmark
while True:
  tmp = cmark.to_html('[this is a link](https://www.google.com)')
  del tmp

Update cmark

Are you still working on this? There have been in a few cmark releases recently, and it would be good to get these integrated. I can open a PR if interested.

The included cmark_export.h is not suited for building on windows

cmark_export.h is normally generated by cmake as appropriate for the platform. Here is what it looks like when using the MS build tools:

#ifndef CMARK_EXPORT_H
#define CMARK_EXPORT_H

#ifdef CMARK_STATIC_DEFINE
#  define CMARK_EXPORT
#  define CMARK_NO_EXPORT
#else
#  ifndef CMARK_EXPORT
#    ifdef libcmark_EXPORTS
        /* We are building this library */
#      define CMARK_EXPORT __declspec(dllexport)
#    else
        /* We are using this library */
#      define CMARK_EXPORT __declspec(dllimport)
#    endif
#  endif

#  ifndef CMARK_NO_EXPORT
#    define CMARK_NO_EXPORT 
#  endif
#endif

#ifndef CMARK_DEPRECATED
#  define CMARK_DEPRECATED __declspec(deprecated)
#endif

#ifndef CMARK_DEPRECATED_EXPORT
#  define CMARK_DEPRECATED_EXPORT CMARK_EXPORT CMARK_DEPRECATED
#endif

#ifndef CMARK_DEPRECATED_NO_EXPORT
#  define CMARK_DEPRECATED_NO_EXPORT CMARK_NO_EXPORT CMARK_DEPRECATED
#endif

#if 0 /* DEFINE_NO_DEPRECATED */
#  ifndef CMARK_NO_DEPRECATED
#    define CMARK_NO_DEPRECATED
#  endif
#endif

#endif

The one included in this repository causes the build to fail on windows. Maybe it could be adjusted to test if _MSC_VER is defined, and then do as above?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.