Mike Slinn

jekyll_run

Published 2020-10-03. Last modified 2023-05-18.
Time to read: 1 minutes.

This page is part of the jekyll_plugins collection.

jekyll_run is a Jekyll tag plugin that executes a program and returns the output from STDOUT. This plugin was designed to be embedded within a {% pre %}{% endpre %} tags. That is why the output includes the command that was executed, and contains unselectable <span> tags.

Installation

Add the following highlighted line to your Jekyll project's Gemfile, within the jekyll_plugins group:

Gemfile
group :jekyll_plugins do 
  gem 'jekyll_run'
end 

And then execute:

Shell
$ bundle

Usage Example

Shell
{% run echo "asdf" %}

The generated HTML is:

Generated HTML
<span class='unselectable'>$ </span>#{@command}\n<span class='unselectable'>#{output}</span>

Which renders as the following, when enclosed within {% pre copyButton dedent label="Rendered output" %}{% endpre %}:

Rendered output
$ echo "asdf" 
asdf

CSS

The CSS similar to the following must be used in order for the plugin to work as shown:

Shell
.unselectable {
  color: #7922f9;
  -moz-user-select: none;
  -khtml-user-select: none;
  user-select: none;
}
* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.