A WordPress Plugin to embed raw.githubusercontent

Working at my post about the dask cluster, I realized that the code snippets presented in the post will eventually change in my GitHub Repo. I wanted to avoid having to make all the changes manually. Therefore, I was looking for a method to automatically include the code for the scripts. Optimally while retaining the code highlighting using SyntaxHighlighter Evolved by Alex Mills. As a quick Google search turns out, there is nothing out there so far. Thus I decided to do the implementation myself.

Basically I just took the code of Alex Mills and wrapped it into a plugin. However that was not enough, since WordPress do not support nested shortcodes. However, there is a way to realize nested shortcodes using the do_shortcode() function. Since the SytaxHighlighter does not use this function, I added a filter to apply the function to all the_content objects using the add_filter() function. add_filter() has a $priority variable, which controls when the filter is applied. Since we modify all the_content choosing a small number here might break your WordPress installation. After taking a look in the SyntaxHighlighter Code I realized that going with priority=9 is a suitable choice.

To Install the Plugin, download Plugin and install using “Plugins ->New Plugin->Upload”.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.