[Pelican] Add GitHub Gist RST Directive to Pelican

Gist is a great tool to share codes. It supports Git version control system, syntax highlighting, and it also provides user a great way to embed the code into web.

In the other hand, anthoer static blog generator OctoPress has a plugin that let user using a simple tag to embed GitHub Gist into thier articles. This feature is awsome, and I really like to have this kind of feature in my Pelican.

Fortunately, it is very simple to add reStructuredText directive in Pelican by using DocUtils register function.

To achieve this, just add the following code into pelican/rstdirectives.py, and every thing works!

I've also put this path into my GitHub Pelican fork, so you could just install this by using the following commands.

# pip uninstall pelican
# pip install git+http://brianhsu@github.com/brianhsu/pelican.git#egg=pelican

After install, you could use .. gist:: [GistID] directive to embed Gist into your article. There is also an option called file you could specify.

For exmaple, if you want embed code like above, you could use the following code in your reStructuredText document.

BTW, this directive will fetch the code at GitHub gist, and put it into a <noscript> tag, so users could read the code in RSS reader normally.

.. gist:: 1407759
   :file: gist.py

Enjoy this, and happy programming.

回響