Class: Nanoc::Filters::Redcarpet

Inherits:
Nanoc::Filter show all
Defined in:
lib/nanoc/filters/redcarpet.rb

Overview

Since:

Constant Summary

Constant Summary

Constants inherited from Nanoc::Filter

Nanoc::Filter::TMP_BINARY_ITEMS_DIR

Instance Attribute Summary

Attributes inherited from Nanoc::Filter

#assigns

Instance Method Summary (collapse)

Methods inherited from Nanoc::Filter

#depend_on, #filename, from_binary?, #initialize, #output_filename, requires, setup, #setup_and_run, to_binary?, type

Methods included from PluginRegistry::PluginMethods

#all, #identifier, #identifiers, #named, #register

Methods inherited from Context

#get_binding, #initialize

Constructor Details

This class inherits a constructor from Nanoc::Filter

Instance Method Details

- (String) run(content, params = {}) - (String) run(content, params = {})

Runs the content through Redcarpet. This method optionally takes processing options to pass on to Redcarpet.

Overloads:

  • - (String) run(content, params = {})

    For Redcarpet 1.x

    Parameters:

    • content (String)

      The content to filter

    Options Hash (params):

    • :options (Array) — default: []

      A list of options to pass on to Redcarpet

    Returns:

    • (String)

      The filtered content

  • - (String) run(content, params = {})

    For Redcarpet 2.x

    Parameters:

    • content (String)

      The content to filter

    Options Hash (params):

    • :options (Hash) — default: {}

      A list of options to pass on to Redcarpet itself (not the renderer)

    • :renderer (::Redcarpet::Render::Base) — default: ::Redcarpet::Render::HTML

      The class of the renderer to use

    • :renderer_options (Hash) — default: {}

      A list of options to pass on to the Redcarpet renderer

    Returns:

    • (String)

      The filtered content

    Since:

    • 3.2.4

Since:

  • 3.2.0



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nanoc/filters/redcarpet.rb', line 42

def run(content, params = {})
  if ::Redcarpet::VERSION > '2'
    options          = params[:options]          || {}
    renderer_class   = params[:renderer]         || ::Redcarpet::Render::HTML
    renderer_options = params[:renderer_options] || {}

    if options.is_a?(Array)
      warn 'WARNING: You are passing an array of options to the :redcarpet filter, but Redcarpet 2.x expects a hash instead. This will likely fail.'
    end

    if renderer_class == ::Redcarpet::Render::HTML_TOC
      renderer = renderer_class.new
    else
      renderer = renderer_class.new(renderer_options)
    end
    ::Redcarpet::Markdown.new(renderer, options).render(content)
  else
    options = params[:options] || []
    ::Redcarpet.new(content, *options).to_html
  end
end