Embed highlighted code snippets from a file.
Embed code snippets from the file system in your Jekyll site.
Add this gem to your site’s Gemfile in the :jekyll_plugins
group:
group :jekyll_plugins do
gem 'octopress-render-code'
end
Then install the gem with Bundler
$ bundle
$ gem install octopress-render-code
Then add the gem to your Jekyll configuration.
gems:
-octopress-render-code
{% render_code <FILE> [options] %}
In your site’s configuration, you can set the directory for embedded code samples.
code_dir: code-examples
The default directory is ‘downloads/code’
Note that order does not matter.
Options | Example | Description |
---|---|---|
lang |
lang:ruby |
Defaults to guessing from file name extension. |
title |
title:"Figure 1.A" |
Add a figcaption title to your code block. |
link_text |
link_text:"Download" |
Text for the link, default: "Raw code" . |
linenos |
lineos:false |
Disable line numbering. |
start |
start:5 |
Start embedding the script from the 5th line number. |
end |
end:15 |
Stop embedding the script after 15th line number. |
range |
range:5-15 |
Embed lines 5-15 of the script. |
mark |
mark:5-7,10 |
Highlight lines of code. This example marks lines 5,6,7 and 10. |
class |
class:"solution" |
Add CSS class name(s) to the code <figure> element. |
Given the existence of a file
{% render figure-1-a.js title:"Figure A: A Simple AJAX Request." mark:5-8
This will
[site_source]/downloads/code/figure-1-a.js
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)