Last active
December 17, 2015 08:29
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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