Mike Slinn
Mike Slinn

jekyll_from_to_until

Published 2020-10-03. Last modified 2023-11-19.
Time to read: 1 minutes.

This page is part of the jekyll_plugins collection.

These filters all return portions of a multiline string. They are all defined in the same plugin. A regular expression is used to specify the match; the simplest regular expression is a string.

  • from – returns the portion beginning with the line that satisfies a regular expression to the end of the multiline string.
  • to – returns the portion from the first line to the line that satisfies a regular expression, including the matched line.
  • until – returns the portion from the first line to the line that satisfies a regular expression, excluding the matched line.

Important: the name of each of these filters must be followed by a colon (:). If you fail to do that an error will be generated and the Jekyll site building process will halt. The error message looks something like this:

Liquid Warning: Liquid syntax error (line xxx): Expected end_of_string but found string in "{{ lines | from 'blah' | xml_escape }}" in /some_directory/some_files.html Liquid Exception: Liquid error (line 285): wrong number of arguments (given 1, expected 2) in /some_directory/some_file.html Error: Liquid error (line 285): wrong number of arguments (given 1, expected 2).

Installation

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

Shell
group :jekyll_plugins do 
  gem 'jekyll_from_to_until'
end 

And then execute:

Shell
$ bundle

from

All of these examples perform identically.
Shell
{{ sourceOfLines | from: 'regex' }}
{{ sourceOfLines | from: "regex" }}
{{ sourceOfLines | from: regex }}

to

All of these examples perform identically.
Shell
{{ sourceOfLines | to: 'regex' }}
{{ sourceOfLines | to: "regex" }}
{{ sourceOfLines | to: regex }}

until

All of these examples perform identically.
Shell
{{ sourceOfLines | until: 'regex' }}
{{ sourceOfLines | until: "regex" }}
{{ sourceOfLines | until: regex }}

Calling From Other Ruby Programs

The methods that implement these filters can be used in other Ruby programs. For an example of how to do this, please refer to the from, to and until option handling in jekyll_flexible_include_plugin.



* 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.