Pure python implementation?


#1

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 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?


#2

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.


#3

Oh, I forgot, there’s also Python-Markdown, though they have the goal of aiming for Gruber-compatibility (link).


#4

I would love to see a Python implementation.

RD


#5

Currently working on a pure python port of stmd.js here. 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)


#6

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


#7

Please do, I was planning on starting after bug fixing


#8

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.


#9

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.


#10

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


#11

I’ve been using CommonMark-py with django-markwhat for django template tags, and it’s working great.


#12

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).


#13

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.


#14

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


#15

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


#16

Well, turns out the bug was in bleach, 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.


#17

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


#18

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.


#19

Is there a packaged cmark Python binding BTW?


#20

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.