The following is a list of all filters that come bundled with Nanoc. Mustache options.
filter invokes the command-line tool of AsciiDoc. This filter takes no options.
For example, the following will convert an AsciiDoc page to HTML:
filter invokes Asciidoctor, a Ruby implementation of AsciiDoc. Unlike the
filter can be customized.
For example, the following will convert an AsciiDoc page to HTML:
filter invokes BlueCloth, a pure-Ruby implementation of Markdown. This filter takes no options.
For example, the following will convert a Markdown page to HTML:
filter runs the content through CoffeeScript. This filter takes no options.
For example, the following will convert CoffeeScript source code into JavaScript:
filter finds code blocks and attempts to syntax-highlight them.
element. The language of the code can be specified in two ways:
element has an HTML class attribute that starts with
, then the remainder of the class attribute will be used as the code language. For example, the following indicates a code block written in Ruby:
If the code block starts with a line that begins with
, then the remainder of the line will be used as the code language. For example, the following indicates a code block written in JSON:
By default, CodeRay will be used to highlight source code. For example, the following will colorize the syntax of all code blocks using CodeRay:
To change the colorizer, pass a symbol containing the name of a colorizer to
. For example, the following highlights all code blocks using Rouge:
filter:colorize_syntax, default_colorizer::rouge
Nanoc knows the following colorizers:
pygmentize, the command-line front end for Pygments, a syntax highlighter written in Python
Rouge, a pure-Ruby syntax highlighter with Pygments-compatible output
To configure individual highlighters, pass the options to the key for the highlighter. For example, the following will set the
filter:colorize_syntax, coderay: { line_numbers::list }
Syntax colorizers can be configured on a per-language basis. To do so, use a
option, passing in a hash where the keys are symbols corresponding to language names, and where the values are symbols corresponding to colorizer names. For example, in the following code snippet, Rouge would be used by default, except for XML, where it uses CodeRay:
filter:colorize_syntax, default_colorizer::rouge, colorizers: { xml::coderay }
filter by default assumes that the content to colorize is an HTML page fragment, rather than a full HTML page, and will therefore not add the HTML boilerplate at the top and bottom of the output. To rather treat the content as a full page, pass
to the filter. Typically, the
option is useful when the content is already fully laid out.
The syntax of the document to highlight is assumed to be HTML by default. To treat the document as XHTML instead, pass
elements even when they are not contained inside a
filter runs the content through eRuby, using the
For example, the following will process ERB source code:
The following example contains ERB code that iterates over all blog posts, and prints them as a header and an excerpt of the body:
ERB supports the following syntax:
, and substitutes the ERB instruction with the result of the expression.
Options
filter takes the following options:
) to use while running this filter. By default, this is 0, which means no taint checks are performed.
The trim mode to use, which changes the way ERB interprets its source. The ERB documentation lists the following trim modes:
enables Ruby code processing for lines beginning with
omit newline for lines starting with
omit newline for lines ending in
omit blank lines ending in
, the initial ERB example above could be written as follows:
Moustache long
filter would have to be called with the proper trim mode set:
filter runs the content through eRuby, using Erubi. Options passed to this filter will be passed on to
For example, the following will process eRuby source code using Erubi:
filter runs the content through eRuby, using Erubis. This filter takes no options.
For example, the following will process eRuby source code using Erubis:
filter runs the content through Haml.
For example, the following will convert Haml into HTML:
The options that are given to this filter will be passed on to
. For example, this filter call set
filter:haml, format::html5
For example, the following will convert Handlebars content into HTML:
Content that is processed using the Handlebars filter can access the following data:
Returns the item attribute with the given name. For example,
in Handlebars are both evaluated as
Returns the layout attribute with the given name. This is only available in layouts. For example,
in Handlebars is evaluated as
Returns the configuration attribute with the given name.
Returns the content to be included in the layout. This is only available in layouts.
For example, this is a basic layout marked up with Handlebars:
This filter does not have any options.
filter invokes kramdown, a fast and featureful pure-Ruby implementation of Markdown. The filter converts to HTML.
For example, the following will convert a Markdown page to HTML:
Parameters that are passed to the filter are passed to
. For example, the following will also convert the content to HTML, as above, but disables the
filter:kramdown, auto_ids: false
filter runs content through Less, a CSS preprocessor.
For example, the following will process Less content:
This filter does not have any options.
filter runs content through Markaby, a method of writing markup as Ruby.
For example, the following will process Markaby content:
This filter does not have any options.
filter runs content through Maruku, a pure-Ruby Markdown-superset interpreter.
For example, the following will process Markdown content using Maruku:
The options that are passed to this filter will be passed on to Maruku’s
For example, the following will convert Mustache content into HTML:
Content that is processed using the Handlebars filter can access the following data:
Returns the item attribute with the given name. For example,
in Handlebars is evaluated as
Returns the content to be included in the layout. This is only available in layouts.
For example, this is a basic layout marked up with Mustache:
This filter does not have any options.
For example, the following will convert Pandoc content into HTML:
filter, pass them as an array for the
key. For example, the following will convert from Markdown to HTML, and enable the
filter runs CSS through Rainpress, a CSS compressor.
For example, the following will compress CSS with Rainpress:
Options passed to this filter will be passed to Rainpress. See the file for a description of the options. For example, the following will retain newlines:
filter:rainpress, newlines: false
For example, the following will convert Markdown content into HTML using RDiscount:
Options can be passed as an array of symbols for the
key. For example, the following will convert from Markdown to HTML, and enable the
filter:rdiscount, extensions: [:smart,:filter_html ]
filter runs content through
For example, the following will convert RDoc content into HTML:
This filter takes no options.
For example, the following will convert Markdown content into HTML via Redcarpet:
This filter takes the following options:
A list of options to pass on to Redcarpet itself (not the renderer)
A list of options to pass on to the Redcarpet renderer
The class of the renderer to use (
Whether or not to add a table of contents
For example, the following will enable fenced code blocks:
filter:redcarpet, options: { fenced_code_blocks: true }
For example, the following will convert Textile content into HTML via RedCloth:
This filter takes the following options:
Set the value for the option key to
to enable or disable the option. For details, see the documentation for
For example, the following disable wrapping caps in a span:
filter:redcloth, no_span_caps: true
filter finds all absolute paths in (X)HTML or CSS content, and converts them into relative paths. This is particularly useful for sites that are not deployed at the root of a domain.
For example, the GitHub Pages site for D★Mark is hosted at https://ddfreyne.github.io/d-mark/. The D★Mark page has a reference to its stylesheet at, which the
filter turns into, so that the stylesheet can be found even if the site is not deployed at the root of the domain.
option specifies the type of content, and can be
. This option must be specified, as the filter cannot reliably determine the type of content by itself.
For example, the following will convert all absolute paths in HTML content to relative ones:
filter:relativize_paths, type::html5
attributes will be relativized. In CSS, all
references will be relativized.
To customize which attributes to normalize in (X)HTML, pass a list of XPath selectors to the
option. Selectors are prefixed with
automatically. For example, the following will only relativize paths if they occur within
attributes on any element anywhere in the document:
If custom namespaces in XHTML are passed to the
option, they also have to be explicitly defined in the
option is a hash where the keys are the prefixes, and the values are the namespace URIs.
To exclude paths from being relativized, use the
option can be any of the following:
The path will not be relativized if the regular expression matches.
The path will not be relativized when the path starts with one or more components that matches the given string.
The path will not be relativized if any of the elements of the array match, using the aforementioned rules for
Indian moustache styles
For example, the following will prevent all paths to /cgi-bin from being relativized:
filter:relativize_paths, type::html5, exclude: ' /cgi-bin '
filter transforms content using RubyPants, which translates plain ASCII punctuation characters into “smart” typographic punctuation HTML entities.
The following will run RubyPants:
This filter takes no options.
filter converts a Sass stylesheet to CSS. For example:
The options that are given to this filter will be passed on to
option. For example, this filter call set
filter:sass, style::compact
You can evaluate Ruby code from within your Sass code using the
Sass function. It takes a string containing Ruby code (a
Sass::Script::Value::String
Sass function can also take an
parameter, which removes quotation marks:
filter produces a source map for a rendered Sass stylesheet. For example:
path = @item.identifier.without_ext + '.css ' filter:sass_sourcemap, css_path: path, sourcemap_path: path + '.map '
filters must be passed the same options.
filter runs the content through Slim, a lightweight templating engine. For example:
Options passed to this filter will be passed to
Slim::Template#initialize
filter runs the content through Typogruby, a Ruby variant of Typogrify for typographically enhancing text. For example:
This filter takes no options.
filter passes JavaScript content through Uglifier, a Ruby wrapper for UglifyJS. For example:
This filter takes options and passes them on to
. For example, the following will disable name mangling and enable support for Harmony mode (ES6/ES2015+):
filter:uglify_js, mangle: false, harmony: true
filter runs the item content through an XSLT stylesheet using Nokogiri.
This filter can only be run for layouts, because it will need both the XML to convert (the item content) as well as the XSLT stylesheet (the layout content).
For example, the following specifies that items matching /reports Additional parameters can be passed to the layout call. These parameters will be turned into elements. For example, the following layout rule adds an additional parameter named filter compresses JavaScript or CSS using the YUICompressor gem. For example, the following compresses CSS content: option must be specified. The option can be set to either , corresponding with CSS and JavaScript. This filter takes options and passes them on to YUICompressor.compress . For details on which options are available, consult the YUICompressor.compress documentation. For example, the following will enable name munging in JavaScript:
Comments
There are no comments for this post "Nanoc » Filters". Be the first to comment...
Add Comment