1

I would like to include highlighted source code within a post.

I know that you can include a gist like this:

{% gist 5555251 %}

But can you also include arbitrary source code from a local file?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958

1 Answers1

3

There are different ways, a bit slow but easy just using something like http://highlightjs.org


Or you can use jekyll with pygments:

Install: apt-get install python-pygments
configure in _config: pygments: true
Create the highlithing css: pygmentize -S default -f html > stylesheets/pygments.css

Don't forget to load the css in your page! source: http://www.stehem.net/2012/02/14/how-to-get-pygments-to-work-with-jekyll.html


Or you can use Github flavored Markdown:

configure in _config: markdown: redcarpet

I'm not sure but i think you need to install the redcarpet gem and pygments manually that it work.

source: Github flavored Markdown and pygments highlighting in Jekyll


Use the SyntaxHighlighter-Plugin

  • Include the source for SyntaxHighlighter you need at minimum: shCore.css, shThemeDefault.css and shCore.js
  • Include for each language the corespondending shBrush.js like shBrushRuby.js for ruby
  • Add at the end of your page <script type="text/javascript">SyntaxHighlighter.all()</script> to inizialize the plugin
  • Wrap your code in {% SyntaxHighlighter lang %} and {% endSyntaxHighlighter %} replace lang by the language of your code
  • Copy SyntaxHighlighter.rb in your _plugins folder

example project https://bitbucket.org/l33tname/jekyll-syntaxhighlighter/src

Community
  • 1
  • 1
Sir l33tname
  • 4,026
  • 6
  • 38
  • 49
  • Is there a way I can use the `{% highlight %}`-tag with [SyntaxHighlighter](http://alexgorbatchev.com/SyntaxHighlighter/contact.html) from Alex Gorbatchev? – Martin Thoma Dec 01 '13 at 13:32
  • I think its possible but for that you need to override the Liquid tag `highlight` or create your own tag http://jekyllrb.com/docs/plugins/#tags and as my knowing there is no plugin out there with the SyntaxHighlighter so I build one, I updating my question – Sir l33tname Dec 01 '13 at 18:23