Skip to content

Instantly share code, notes, and snippets.

@kfr2
Last active December 17, 2015 08:29
Show Gist options
  • Save kfr2/5580453 to your computer and use it in GitHub Desktop.
Save kfr2/5580453 to your computer and use it in GitHub Desktop.
A Pelican plugin to convert "[[ gist username:ID ]]" in an article into its embedded <script> equivalent.
import re
from pelican import signals
def gist(content):
"""Converts [[ gist username:ID ]] in an article into its embedded <script> equivalent."""
pattern = r'\[\[ gist (\w+):(\d+) \]\]'
replacement = r'<script src="https://gist.github.com/\1/\2.js"></script>'
content._content = re.sub(pattern, replacement, unicode(content._content))
def register():
signals.content_object_init.connect(gist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment