# Pure python implementation?

**URL:** <https://talk.commonmark.org/t/pure-python-implementation/623>\
**Category:** Implementation\
**Created:** [September 17, 2014, 12:10pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623 "2014-09-17T12:10:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lu\_zero](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/lu_zero/32/557_2.png) [@lu\_zero](https://talk.commonmark.org/u/lu_zero)\
**Post date:** [September 17, 2014, 12:10pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/1 "2014-09-17T12:10:49Z")

</div>

Currently python is lacking decent markdown support (nothing equivalent to kramdown to have a proper parse tree and a good featureset).

Right now the closest implementation I found is [mistune](https://github.com/lepture/mistune/) it is quite fast compared to the normal pure python markdown and in pure interpreter mode it is just 20x slower than C (using cython to speed it up makes it quite compelling).

The author isn’t interested in spending time on commonmark though.

Anybody knows of an implementation or is willing to work on mistune?

---

<div class="post-metadata">

**Author:** ![Prashant\_Kumar](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/prashant_kumar/32/403_2.png) [@Prashant\_Kumar](https://talk.commonmark.org/u/Prashant_Kumar)\
**Post date:** [September 17, 2014, 6:50pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/2 "2014-09-17T18:50:00Z")

</div>

Hey, I’ve actually started work on a pure Python translation of the reference JS implementation.  
I’m at the midway point, inline parser translated, doc parser to go.  
My plan is get it passing the tests, then get it Pythonic. I’ll throw up a git repository of what I have this evening.

I don’t know too much about python packaging, and I know Windows users discover they have difficulty installing numpy because they don’t have VS2008. I was wondering on the relative merits of translating to pure python vs simply python bindings to the reference C implementation.

---

<div class="post-metadata">

**Author:** ![Prashant\_Kumar](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/prashant_kumar/32/403_2.png) [@Prashant\_Kumar](https://talk.commonmark.org/u/Prashant_Kumar)\
**Post date:** [September 17, 2014, 6:52pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/3 "2014-09-17T18:52:33Z")

</div>

Oh, I forgot, there’s also [Python-Markdown](https://pypi.python.org/pypi/Markdown), though they have the goal of aiming for Gruber-compatibility ([link](https://github.com/waylan/Python-Markdown/issues/338)).

---

<div class="post-metadata">

**Author:** ![Rick](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/rick/32/420_2.png) [@Rick](https://talk.commonmark.org/u/Rick)\
**Post date:** [September 20, 2014, 3:26am UTC](https://talk.commonmark.org/t/pure-python-implementation/623/4 "2014-09-20T03:26:56Z")

</div>

I would love to see a Python implementation.

RD

---

<div class="post-metadata">

**Author:** ![rolandshoemaker](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/rolandshoemaker/32/441_2.png) [@rolandshoemaker](https://talk.commonmark.org/u/rolandshoemaker)\
**Post date:** [September 20, 2014, 10:23am UTC](https://talk.commonmark.org/t/pure-python-implementation/623/5 "2014-09-20T10:23:07Z")

</div>

Currently working on a pure python port of stmd.js [here](https://github.com/rolandshoemaker/CommonMark-py). Still working on getting it to pass tests so contributors welcome… (although hopefully it should be finished after this weekend, or at least up to date with stmd.js)

---

<div class="post-metadata">

**Author:** ![lu\_zero](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/lu_zero/32/557_2.png) [@lu\_zero](https://talk.commonmark.org/u/lu_zero)\
**Post date:** [September 23, 2014, 8:18am UTC](https://talk.commonmark.org/t/pure-python-implementation/623/6 "2014-09-23T08:18:34Z")

</div>

I had a look, do you mind if I start to pep8 the codebase? pyflake/pep8 are quite noisy right now =)

---

<div class="post-metadata">

**Author:** ![rolandshoemaker](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/rolandshoemaker/32/441_2.png) [@rolandshoemaker](https://talk.commonmark.org/u/rolandshoemaker)\
**Post date:** [September 23, 2014, 9:37pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/7 "2014-09-23T21:37:04Z")

</div>

Please do, I was planning on starting after bug fixing

---

<div class="post-metadata">

**Author:** ![rolandshoemaker](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/rolandshoemaker/32/441_2.png) [@rolandshoemaker](https://talk.commonmark.org/u/rolandshoemaker)\
**Post date:** [September 25, 2014, 9:59am UTC](https://talk.commonmark.org/t/pure-python-implementation/623/8 "2014-09-25T09:59:22Z")

</div>

This is pretty much finished now, it currently fails some entity and link tests (as stmd.js does) since it isn’t escaping URLs and replacing entities like &ouml, but I should finish that soon.

---

<div class="post-metadata">

**Author:** ![lu\_zero](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/lu_zero/32/557_2.png) [@lu\_zero](https://talk.commonmark.org/u/lu_zero)\
**Post date:** [September 28, 2014, 11:21pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/9 "2014-09-28T23:21:39Z")

</div>

Looks like it progressed a lot while I wasn’t watching and looks already great.

Now I should find some time and check how hard would be wire it in docutils (so sphinx could use commonmark) or in moin2.

---

<div class="post-metadata">

**Author:** ![rolandshoemaker](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/rolandshoemaker/32/441_2.png) [@rolandshoemaker](https://talk.commonmark.org/u/rolandshoemaker)\
**Post date:** [September 29, 2014, 12:09am UTC](https://talk.commonmark.org/t/pure-python-implementation/623/10 "2014-09-29T00:09:39Z")

</div>

That would be awesome! Please let me know if you end up incorporating it into anything else, I’d love to know.

---

<div class="post-metadata">

**Author:** ![nikolas](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/nikolas/32/714_2.png) [@nikolas](https://talk.commonmark.org/u/nikolas)\
**Post date:** [June 11, 2015, 4:09pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/11 "2015-06-11T16:09:17Z")

</div>

I’ve been using [CommonMark-py](https://github.com/rolandshoemaker/CommonMark-py) with [django-markwhat](https://github.com/Alir3z4/django-markwhat) for django template tags, and it’s working great.

---

<div class="post-metadata">

**Author:** ![jgm](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/jgm/32/1360_2.png) [@jgm](https://talk.commonmark.org/u/jgm)\
**Post date:** [June 11, 2015, 7:36pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/12 "2015-06-11T19:36:24Z")

</div>

The last commit in rolandshoemaker/CommonMark-py is from  
October 2014. So it can’t be up to date with the current  
spec (or even close).

---

<div class="post-metadata">

**Author:** ![lu\_zero](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/lu_zero/32/557_2.png) [@lu\_zero](https://talk.commonmark.org/u/lu_zero)\
**Post date:** [June 11, 2015, 8:20pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/13 "2015-06-11T20:20:01Z")

</div>

I cherry-backported a couple of fixes from the js update (lists and another) in my repository, but I’m tempted to refactor the codebase to match closely the current javascript. Sadly my time right now is scarce.

---

<div class="post-metadata">

**Author:** ![nikolas](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/nikolas/32/714_2.png) [@nikolas](https://talk.commonmark.org/u/nikolas)\
**Post date:** [September 8, 2015, 9:20pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/14 "2015-09-08T21:20:08Z")

</div>

I’ve run into some issues with CommonMark-py encoding HTML in the wrong ways in code blocks, so I’ll work on the testing stuff and see if I can get a fix into your fork of this here: [https://github.com/lu-zero/CommonMark-py](https://github.com/lu-zero/CommonMark-py)

---

<div class="post-metadata">

**Author:** ![lu\_zero](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/lu_zero/32/557_2.png) [@lu\_zero](https://talk.commonmark.org/u/lu_zero)\
**Post date:** [September 9, 2015, 2:23am UTC](https://talk.commonmark.org/t/pure-python-implementation/623/15 "2015-09-09T02:23:48Z")

</div>

Thanks a lot, I enabled travis on my branch so will be easier to check that.

---

<div class="post-metadata">

**Author:** ![nikolas](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/nikolas/32/714_2.png) [@nikolas](https://talk.commonmark.org/u/nikolas)\
**Post date:** [September 14, 2015, 1:55pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/16 "2015-09-14T13:55:09Z")

</div>

Well, turns out the bug was in [bleach](https://github.com/jsocol/bleach/pull/162), not CommonMark-py. I would like to get CommonMark-py up to date with the latest spec, though.

I’ll try and start this work, using commonmark.js as a reference.

---

<div class="post-metadata">

**Author:** ![nikolas](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/nikolas/32/714_2.png) [@nikolas](https://talk.commonmark.org/u/nikolas)\
**Post date:** [December 10, 2015, 2:33am UTC](https://talk.commonmark.org/t/pure-python-implementation/623/17 "2015-12-10T02:33:19Z")

</div>

It looks like the Read the Docs project will take over maintenance of CommonMark-py, so this is the new repo location: [https://github.com/rtfd/CommonMark-py](https://github.com/rtfd/CommonMark-py)

---

<div class="post-metadata">

**Author:** ![nikolas](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/nikolas/32/714_2.png) [@nikolas](https://talk.commonmark.org/u/nikolas)\
**Post date:** [February 3, 2016, 5:05pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/18 "2016-02-03T17:05:45Z")

</div>

For anyone following this – as of about a month ago, rtfd’s CommonMark-py library mentioned above is now compliant with the latest commonmark spec (0.24). I’ll be trying to keep this library up to date, and any help and suggestions are welcome.

---

<div class="post-metadata">

**Author:** ![cirosantilli](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/cirosantilli/32/145_2.png) [@cirosantilli](https://talk.commonmark.org/u/cirosantilli)\
**Post date:** [May 10, 2016, 10:41pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/19 "2016-05-10T22:41:08Z")

</div>

Is there a packaged cmark Python binding BTW?

---

<div class="post-metadata">

**Author:** ![jgm](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/jgm/32/1360_2.png) [@jgm](https://talk.commonmark.org/u/jgm)\
**Post date:** [May 11, 2016, 5:21pm UTC](https://talk.commonmark.org/t/pure-python-implementation/623/20 "2016-05-11T17:21:24Z")

</div>

Not that I know of, but see `wrappers/wrapper.py` in the cmark repository for an example of how easy it is to use cmark via the ctypes library.
