Class: Markdown::HTMLPipeline
- Inherits:
-
Object
- Object
- Markdown::HTMLPipeline
- Defined in:
- lib/jekyll-html-pipeline.rb
Instance Method Summary collapse
- #convert(content) ⇒ Object
- #ensure_default_opts ⇒ Object
- #filter?(filter) ⇒ Boolean
- #filter_key(key) ⇒ Object
-
#initialize(config) ⇒ HTMLPipeline
constructor
A new instance of HTMLPipeline.
- #setup ⇒ Object
- #symbolize_keys(hash) ⇒ Object
Constructor Details
#initialize(config) ⇒ HTMLPipeline
Returns a new instance of HTMLPipeline.
6 7 8 9 10 11 |
# File 'lib/jekyll-html-pipeline.rb', line 6 def initialize(config) require 'html/pipeline' @config = config @errors = [] @setup = false end |
Instance Method Details
#convert(content) ⇒ Object
73 74 75 76 |
# File 'lib/jekyll-html-pipeline.rb', line 73 def convert(content) setup @parser.to_html(content) end |
#ensure_default_opts ⇒ Object
38 39 40 41 42 43 |
# File 'lib/jekyll-html-pipeline.rb', line 38 def ensure_default_opts @config['html_pipeline']['filters'] ||= ['markdownfilter'] @config['html_pipeline']['context'] ||= { 'gfm' => true } # symbolize strings as keys, which is what HTML::Pipeline wants @config['html_pipeline']['context'] = symbolize_keys(@config['html_pipeline']['context']) end |
#filter?(filter) ⇒ Boolean
17 18 19 20 21 |
# File 'lib/jekyll-html-pipeline.rb', line 17 def filter?(filter) filter < HTML::Pipeline::Filter rescue LoadError, ArgumentError false end |
#filter_key(key) ⇒ Object
13 14 15 |
# File 'lib/jekyll-html-pipeline.rb', line 13 def filter_key(key) key.to_s.downcase.to_sym end |
#setup ⇒ Object
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 |
# File 'lib/jekyll-html-pipeline.rb', line 45 def setup return if @setup ensure_default_opts filters = @config['html_pipeline']['filters'].map do |filter| if filter?(filter) filter else key = filter_key(filter) begin const_filter = HTML::Pipeline.constants.find { |c| c.downcase == key } # probably a custom filter if const_filter.nil? Jekyll::Converters.const_get(filter) else HTML::Pipeline.const_get(const_filter) end rescue StandardError => e raise LoadError, e end end end @parser = HTML::Pipeline.new(filters, @config['html_pipeline']['context']) @setup = true end |
#symbolize_keys(hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/jekyll-html-pipeline.rb', line 23 def symbolize_keys(hash) hash.each_with_object({}) do |(key, value), result| new_key = case key when String then key.to_sym else key end new_value = case value when Hash then symbolize_keys(value) when Array then value.map(&:to_sym) else value end result[new_key] = new_value end end |