require 'albino' require 'nokogiri' before 'index.html.haml' do @readme = Nokogiri::HTML(render('../README.md')).css('body') # Remove everything before the first

tag @readme.children.each do |node| break if node.name == 'h2' node.remove end # Link

and

tags @links = @readme.css('h2, h3').collect do |node| href = node.text.downcase.gsub(/\s/, '_') name = node.text node.inner_html = '' + node.inner_html + '' if node.name == 'h2' { :name => name, :href => href } else nil end end @links.compact! @readme.css('pre').each do |pre| # Retrieve language from comment highlight = nil language = nil comment = pre.previous.previous if comment && comment.comment? highlight = comment.content.match(/highlight:(\S+)/) language = comment.content.match(/language:(\S+)/) highlight = highlight[1].split(',') if highlight language = language[1] if language end highlight ||= [] language ||= :ruby # Insert
 tags before the previous element (because its floated right)
    unless pre.previous_element.name == 'h2'
      pre.previous_element.add_previous_sibling(pre)
    end

    # Insert 
before each
 tag
    pre.add_previous_sibling('
') # Pygmentize pygmented = Albino.colorize(pre.css('code').text, language) # Highlight highlight.each do |str| pygmented = pygmented.gsub(str, '' + str + '') end # Replace
    pre.replace pygmented
  end
  
  # Insert 
before each

tag @readme.css('h3').each do |h3| h3.add_previous_sibling('
') end # Replace colons at the end of

tags with arrows. @readme.css('p').each do |p| p.inner_html = p.inner_html.strip.gsub(/:$/, '') end @readme = @readme.inner_html end