Class: Nanoc::Filters::Redcarpet Private
- Inherits:
-
Nanoc::Filter
- Object
- Int::Context
- Nanoc::Filter
- Nanoc::Filters::Redcarpet
- Defined in:
- lib/nanoc/filters/redcarpet.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary
Constants inherited from Nanoc::Filter
Nanoc::Filter::TMP_BINARY_ITEMS_DIR
Instance Attribute Summary
Attributes inherited from Nanoc::Filter
Instance Method Summary collapse
-
#run(content, params = {}) ⇒ Object
private
Runs the content through [Redcarpet](github.com/vmg/redcarpet).
Methods inherited from Nanoc::Filter
#depend_on, #filename, from_binary?, #initialize, #output_filename, requires, setup, #setup_and_run, to_binary?, type
Methods included from Int::PluginRegistry::PluginMethods
#all, #identifier, #identifiers, #named, #register
Methods inherited from Int::Context
Constructor Details
This class inherits a constructor from Nanoc::Filter
Instance Method Details
#run(content, params = {}) ⇒ String #run(content, params = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Runs the content through [Redcarpet](github.com/vmg/redcarpet). This method optionally takes processing options to pass on to Redcarpet.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nanoc/filters/redcarpet.rb', line 43 def run(content, params = {}) if ::Redcarpet::VERSION > '2' = params.fetch(:options, {}) renderer_class = params.fetch(:renderer, ::Redcarpet::Render::HTML) = params.fetch(:renderer_options, {}) with_toc = params.fetch(:with_toc, false) if .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 # Setup TOC if with_toc unless renderer_class <= ::Redcarpet::Render::HTML raise "Unexpected renderer: #{renderer_class}" end # `with_toc` implies `with_toc_data` for the HTML renderer [:with_toc_data] = true end # Create renderer renderer = if renderer_class == ::Redcarpet::Render::HTML_TOC renderer_class.new else renderer_class.new() end # Render if with_toc renderer_toc = ::Redcarpet::Render::HTML_TOC.new toc = ::Redcarpet::Markdown.new(renderer_toc, ).render(content) body = ::Redcarpet::Markdown.new(renderer, ).render(content) toc + body else ::Redcarpet::Markdown.new(renderer, ).render(content) end end end |