class Yarrow::Format::Markdown

Public Class Methods

new(source) click to toggle source
# File lib/yarrow/format/markdown.rb, line 6
def initialize(source)
  @source = source.to_s
  @document = Kramdown::Document.new(@source)
end

Public Instance Methods

title() click to toggle source
# File lib/yarrow/format/markdown.rb, line 27
def title
  @title ||= select_title
end
to_dom() click to toggle source
# File lib/yarrow/format/markdown.rb, line 15
def to_dom
  @document.root
end
to_html() click to toggle source
# File lib/yarrow/format/markdown.rb, line 19
def to_html
  @document.to_html
end
to_s() click to toggle source
# File lib/yarrow/format/markdown.rb, line 11
def to_s
  @source
end

Private Instance Methods

select_title() click to toggle source
# File lib/yarrow/format/markdown.rb, line 50
def select_title
  stack = to_dom.children
  
  while !stack.empty?
    next_el = stack.pop
  
    if next_el.type == :header and next_el.options[:level] == 1
      return next_el.options[:raw_text]
    else
      stack.concat(next_el.children) if next_el.children
    end
  end
  
  nil
end