6.5 KiB
layout | title | prev_section | next_section |
---|---|---|---|
docs | Templates | migrations | permalinks |
Jekyll uses the Liquid templating language to process templates. All of the standard Liquid tags and filters are supported, Jekyll even adds a few handy filters and tags of its own to make common tasks easier.
Filters
Description | Filter and Output |
---|---|
Date to XML Schema Convert a Date into XML Schema format. |
|
Date to String Convert a date to short format. |
|
Date to Long String Format a date to long format. |
|
XML Escape Escape some text for use in XML. |
|
CGI Escape CGI escape a string for use in a URL. Replaces any special characters with appropriate %XX replacements. |
|
Number of Words Count the number of words in some text. |
|
Array to Sentence Convert an array into a sentence. Useful for listing tags. |
|
Textilize Convert a Textile-formatted string into HTML, formatted via RedCloth |
|
Markdownify Convert a Markdown-formatted string into HTML. |
|
Tags
Includes (Partials)
If you have small page fragments that you wish to include in multiple
places on your site, you can use the include
tag.
{% highlight ruby %} {{ "{% include sig.textile " }}%} {% endhighlight %}
Jekyll expects all include files to be placed in an _includes
directory at the root of your source dir. So this will embed the
contents of /path/to/your/site/_includes/sig.textile
into the calling
file.
Code snippet highlighting
Jekyll has built in support for syntax highlighting of over 100
languages thanks to
Pygments. In order to take advantage of this
you’ll need to have Pygments installed, and the pygmentize
binary must
be in your $PATH
. When you run Jekyll, make sure you run it with
Pygments enabled.
To render a code block with syntax highlighting, surround your code as follows:
{% highlight ruby %} {{ "{% highlight ruby " }}%} def foo puts 'foo' end {{ "{% endhighlight " }}%} {% endhighlight %}
The argument to the highlight
tag (ruby
in the example above) is the language identifier. To find the appropriate identifier to use for the language you want to highlight, look for the “short name” on the Lexers page.
Line numbers
There is a second argument to highlight
called linenos
that is
optional. Including the linenos
argument will force the highlighted
code to include line numbers. For instance, the following code block
would include line numbers next to each line:
{% highlight ruby %} {{ "{% highlight ruby linenos " }}%} def foo puts 'foo' end {{ "{% endhighlight " }}%} {% endhighlight %}
Stylesheets for syntax highlighting
In order for the highlighting to show up, you’ll need to include a
highlighting stylesheet. For an example stylesheet you can look at
syntax.css.
These are the same styles as used by GitHub and you are free to use them
for your own site. If you use linenos, you might want to include an
additional CSS class definition for the .lineno
class in syntax.css
to
distinguish the line numbers from the highlighted code.
Post URL
If you would like to include a link to a post on your site, the post_url
tag will generate the correct permalink URL for the post you specify.
{% highlight bash %} {{ "{% post_url 2010-07-21-name-of-post " }}%} {% endhighlight %}
There is no need to include the file extension when using the post_url
tag.
You can also use this tag to create a link to a post in Markdown as follows:
{% highlight html %} [Name of Link]({{ "{% post_url 2010-07-21-name-of-post " }}%}) {% endhighlight %}