Reputation: 5459
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
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
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
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
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
Reputation: 16776
Python has its own Markup language that is fairly similar to Markdown: http://docutils.sourceforge.net/rst.html
Upvotes: 1