Adding Syntax Highlighting to a Ghost Blog

Adding Syntax Highlighting to a Ghost Blog

I recently added syntax highlighting of code examples to my blog using highlight.js.

First, head on over to the highlight.js website and grab a copy of the library. You can also link to it off of a CDN. Next, you'll either need to put the stylesheet and script in your theme, or add them to head section of the page using the Ghost control panel.

That's all it takes. Highlight.js is compatible with the markup that Ghost generates for fenced code blocks. As a bonus, you can specify the language in the fenced code block to use, as in the following example.

    ```java
    public class Example implements Highlighted {
    }
    ```
public class Example implements Highlighted {
}
Mastodon