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_key(s) ⇒ Object
-
#initialize(config) ⇒ HTMLPipeline
constructor
A new instance of HTMLPipeline.
- #is_filter?(f) ⇒ Boolean
- #setup ⇒ Object
- #symbolize_keys(hash) ⇒ Object
Constructor Details
#initialize(config) ⇒ HTMLPipeline
Returns a new instance of HTMLPipeline.
4 5 6 7 8 |
# File 'lib/jekyll-html-pipeline.rb', line 4 def initialize(config) require 'html/pipeline' @config = config @errors = [] end |
Instance Method Details
#convert(content) ⇒ Object
70 71 72 73 |
# File 'lib/jekyll-html-pipeline.rb', line 70 def convert(content) setup @parser.to_html(content) end |
#ensure_default_opts ⇒ Object
35 36 37 38 39 40 |
# File 'lib/jekyll-html-pipeline.rb', line 35 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_key(s) ⇒ Object
10 11 12 |
# File 'lib/jekyll-html-pipeline.rb', line 10 def filter_key(s) s.to_s.downcase.to_sym end |
#is_filter?(f) ⇒ Boolean
14 15 16 17 18 |
# File 'lib/jekyll-html-pipeline.rb', line 14 def is_filter?(f) f < HTML::Pipeline::Filter rescue LoadError, ArgumentError false end |
#setup ⇒ Object
42 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 |
# File 'lib/jekyll-html-pipeline.rb', line 42 def setup unless @setup ensure_default_opts filters = @config['html_pipeline']['filters'].map do |f| if is_filter?(f) f else key = filter_key(f) begin filter = HTML::Pipeline.constants.find { |c| c.downcase == key } # probably a custom filter if filter.nil? Jekyll::Converters.const_get(f) else HTML::Pipeline.const_get(filter) end rescue Exception => e raise LoadError.new(e) end end end @parser = HTML::Pipeline.new(filters, @config['html_pipeline']['context']) @setup = true end end |
#symbolize_keys(hash) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jekyll-html-pipeline.rb', line 20 def symbolize_keys(hash) hash.inject({}){|result, (key, value)| new_key = case key when String then key.to_sym else key end new_value = case value when Hash then symbolize_keys(value) else value end result[new_key] = new_value result } end |