In preparation for writing some more technical blog posts (like the previous one on writing Python, which I'm really excited about!), I have been needing to figure out exactly how syntax highlighting works in the Ghostium/Ghost framework that this blog is built on.

What's Supported?

Perhaps it's clearer to others who have come across this more often, but this implementation of Markdown supports Github Flavored Markdown style Language Specifiers. This is becoming more and more common among the tech community. The problem is that it's unclear what supported by my setup.

To understand where to find where the support come from, one must have an understanding of the way that Ghost has decided to implement thier system. Code syntax highlighting is not considered a core feature, so it's being saved for the plugins system, which hasn't come yet. So the syntax highlighting that I have is supported by Ghostium, the theme.

Ghostium itself points to Prism.js as its sytax highlighting engine. Thus, to figure out what language keywords that Prism supports, I had to dig into the Prism source code.

Luckily, Prism is a well documented open source project, and all it took was a search of the source on Github to find what I was looking for. So, for posterity's sake, here's a full list of language key words supported by Prism.

Languages

  • markup
  • css
  • css-extras
  • clike
  • javascript
  • java
  • php
  • php-extras
  • coffeescript
  • scss
  • bash
  • c
  • cpp
  • python
  • sql
  • groovy
  • http
  • ruby
  • gherkin
  • csharp
  • go
  • nsis

It's worth noting that some of these aren't actually languages! For instance, clike. And, if one find that a language is missing, Prism is easily extensible.

A Remaining Mystery

So great! I'm in business with all these languages.

Wrong.

Through some testing (on this post), I found that some languages that should be supported, were in fact not. This is caused by the author of Ghostium choosing to use only a minimum version of Prism. Though I understand and respect Oswaldo's decision, not having Python syntax highlighting won't do!

The Solution

As Oswaldo suggests, the best way to handle this problem is to rebuild the theme yourself, with a fuller version of Prism. Luckily, some fellow users of Ghostium have already discovered this issue, and have tried to add a guide to do this. It is not done, and is currently not in the main repository. Thus, it remained unclear exactly how to approach this issue.

A Workaround

Though it is not required to download a new version of Prism, it is not entirely clear how to rebuild the version of Prism downloaded by Bower in Ghostium. The easiest work around is to follow the earlier version of the guide until you have to run grunt. At this point, instead run grunt dryrun, as suggested by a later version of the guide. Before you do this however, I recommend backing up built files! Any customizations will be overwritten. What I ended up doing was saving everything to a git repository, then re-checking out everything in the partials directory. This is kind of hacky, and hopefully a better guide to how to do this will emerge from the project.

Done Is Beautfiul

However, it gets the job done! I was able to add a bunch more languages to my theme (though not all the ones above, I've never even heard of Groovy). Check out the examples below.

Some Examples

c

int  
main (int argc, char ** argv)  
{
    printf("Hello World!\n");

    return 0;
}

python

def main():  
    print('Hello, world!')

if __name__ == "__main__":  
    main()

javascript

$(document).ready(function(){
    console.log('Hello, world!');
});