Published 2020-10-03.
Last modified 2023-05-18.
Time to read: 1 minutes.
jekyll_plugins
collection, categorized under Jekyll.
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:
group :jekyll_plugins do gem 'jekyll_from_to_until' end
And then execute:
$ bundle
from
All of these examples perform identically.{{ sourceOfLines | from: 'regex' }} {{ sourceOfLines | from: "regex" }} {{ sourceOfLines | from: regex }}
to
All of these examples perform identically.{{ sourceOfLines | to: 'regex' }} {{ sourceOfLines | to: "regex" }} {{ sourceOfLines | to: regex }}
until
All of these examples perform identically.{{ sourceOfLines | until: 'regex' }} {{ sourceOfLines | until: "regex" }} {{ sourceOfLines | until: regex }}