24

Does anyone knows of a working Python GFM implementation?

Currently I'm using a javascript renderer. It works, but an actual Python renderer would be the right tool for the job. (FS is a Django app)

I tried combining this with this. But the results are not so good.

relevant code --> https://github.com/freedomsponsors/www.freedomsponsors.org/blob/master/djangoproject/core/models.py (see IssueComment.toHTML)

Syntax highlighting is a plus.

6 Answers 6

19

GitHub uses Redcarpet which is really a Ruby binding built by github for Sundown.

There's a binding for Sundown in Python called Misaka. If you want to have something closer to the renderer github uses but in python you might start there.

For code highlighting you can use Pygments with Misaka.

1
  • 2
    This is how I made it work. If someone else is planning to use misaka, please beware of this Sep 5, 2012 at 11:47
9

Python-Markdown plus py-gfm seems to work well. It has the benefit of being somewhat standardized within the Python ecosystem - several extensions for Python-Markdown are available, then additional packages like django_markdown can be built on top of Python-Markdown and benefit from its extensions.

1
  • 2
    As the new maintainer of py-gfm, I'll try to add missing features in future releases.
    – zopieux
    Mar 4, 2016 at 21:19
6

In case helpful for others, I just wanted the Github fenced code syntax, e.g.

```python
def hello():
   print('this should be rendered properly')
```

Python Markdown actually ships with an extension to do this already called Fenced Code Blocks that works well.

You just call it like so:

page_content = markdown.markdown(source, extensions=[FencedCodeExtension()])
2

Grip is also pretty cool and gets the job done.

1

Python has its own Markup language that is fairly similar to Markdown: http://docutils.sourceforge.net/rst.html

1
  • 1
    Thanks, that's good to know (upvoted). I'd rather use md though. Aug 14, 2012 at 2:14
1

Github Flavored Markdown in Python (gist)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.