Tony Lâmpada
Tony Lâmpada

Reputation: 5459

Github-Flavored-Markdown in Python

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.

Upvotes: 27

Views: 14443

Answers (7)

Dominik Peters
Dominik Peters

Reputation: 242

The cmarkgfm package provides Python bindings to GitHub's fork of cmark so that "rendering is compliant with GitHub's, since this package wraps GitHub's own C parser and serializer" (according to the pycmarkgfm package which is very similar but less recently maintained).

Upvotes: 0

Eduardo
Eduardo

Reputation: 22834

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.

Upvotes: 20

Cory
Cory

Reputation: 24260

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()])

Upvotes: 6

Josh Kelley
Josh Kelley

Reputation: 58352

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.

Upvotes: 9

Anto
Anto

Reputation: 7202

Grip is also pretty cool and gets the job done.

Upvotes: 2

Davoud Taghawi-Nejad
Davoud Taghawi-Nejad

Reputation: 16776

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

Upvotes: 1

Related Questions