Class: Nanoc::Filters::Redcarpet
- Inherits:
-
Nanoc::Filter
- Object
- Context
- Nanoc::Filter
- Nanoc::Filters::Redcarpet
- Defined in:
- lib/nanoc/filters/redcarpet.rb
Overview
Constant Summary
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)
-
- (Object) run(content, params = {})
@return [String] The filtered content.
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
Constructor Details
This class inherits a constructor from Nanoc::Filter
Instance Method Details
- (Object) run(content, params = {})
@return [String] The filtered content
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 |
# 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 if renderer_class == ::Redcarpet::Render::HTML_TOC renderer = renderer_class.new else renderer = 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 |