No commit activity in last 3 years
No release in over 3 years
A Liquid tag plugin for Jekyll that replaces the built in highlight tag, and allows passing the language to highlight in as a liquid variable.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.6
>= 3.6.3
 Project Readme

jekyll-highlight-param

Gem Version

A Liquid tag plugin for Jekyll that replaces the built in {% highlight %} tag, and allows passing the language to highlight in as a parameter.

An issue for making this change a part of the mainline Jekyll Highlight tag can be found here.

It appears v0.0.1 did not actually work as intended, and was simply failing gracefully by detecting the language from the code itself. A better job of detecting errors and alerting the user was devised in v0.0.2.

Installation

Add this line to your application's Gemfile:

group :jekyll_plugins do
    gem 'jekyll-highlight-param', :github => 'UriShX/jekyll-highlight-param'
end

And then execute:

$ bundle

Or install it yourself as:

$ gem install jekyll-highlight-param

Then add the following to your site's _config.yml:

plugins:
  - jekyll-highlight-param

💡 If you are using a Jekyll version less than 3.5.0, use the gems key instead of plugins.

Usage

Basic usage

Basic usage is the same as Jekyll's {% highlight %} tag, i.e.:

{% highlight_param ruby %}
def foo
  puts 'foo'
end
{% endhighlight_param %}

Using variables names for the language

Please note: Since v0.0.2 passing variables to the highlight_param tag is done in a similar way to the syntax for passing variables to other tags, such as link. This is a breaking change from v0.0.1.

The name of the language you for the code to be highlighted can be specified as a variable instead of specifying the language directly in the template. For example, suppose you defined a variable in your page's front matter like this:

---
title: My page
my_code: footer_company_a.html
my_lang: liquid
---

You could then reference that variable in your highlight:

{% if page.my_variable %}
  {% capture my_code %}
    {% include {{ page.code }} %}
  {% endcapture %}
  {% highlight_param {{ page.my_lang }} %}
    {{ my_code | strip }}
  {% endhighlight_param %}
{% endif %}

In this example, the capture will store the include file _includes/footer_company_a.html, then the highlight will would match the display to match the syntax of liquid.

Line numbers

You could also pass a line numbers argument, as in the original {% highlight %} tag, both as parameter and as a variable. Line numbers are enabled when passing the linenos argument, and disabled as default.

{% highlight_param ruby linenos %}
def foo
  puts 'foo'
end
{% endhighlight_param %}

or:

---
title: My page
line_numbers: linenos
---
{% highlight_param ruby {{ page.line_numbers }} %}
def foo
  puts 'foo'
end
{% endhighlight_param %}

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request