Class: Benoit::Filters::MarkdownFilter

Inherits:
BaseFilter
  • Object
show all
Defined in:
lib/benoit/filters/markdown_filter.rb

Instance Attribute Summary

Attributes inherited from BaseFilter

#current_site

Class Method Summary collapse

Methods inherited from BaseFilter

build_output, #builder, #generate_output, output_name, #output_name_generator

Class Method Details

.extract_layout(content) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/benoit/filters/markdown_filter.rb', line 27

def self.extract_layout(content)
  first_nonblank_line =
    content.lines.find_index do |line|
      line !~ /extends/ and line.strip != ""
    end
  content.lines.to_a[first_nonblank_line..-1].join("")
end

.prepend_layout(final_content, layout) ⇒ Object



35
36
37
38
# File 'lib/benoit/filters/markdown_filter.rb', line 35

def self.prepend_layout(final_content, layout)
  extends_line = %{{% extends "#{layout}" %}\n\n}
  %{#{extends_line}#{final_content}}
end

.preserving_layout(layout, content, &block) ⇒ Object



20
21
22
23
24
25
# File 'lib/benoit/filters/markdown_filter.rb', line 20

def self.preserving_layout(layout, content, &block)
  content = extract_layout(content) if layout
  output = block.call(content)
  output = prepend_layout(output, layout) if layout
  output
end

.render_markdown(engine, content, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/benoit/filters/markdown_filter.rb', line 40

def self.render_markdown(engine, content, options={})
  case engine
  when :redcarpet
    markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, fenced_code_blocks: true, filter_html: true)
    markdown.render(content)
  when :kramdown
    Kramdown::Document.new(content).to_html
  end
end