tent.io/lib/markdown_html.rb
2012-10-07 12:23:17 -04:00

24 lines
567 B
Ruby

require 'pygments.rb'
class MarkdownHTML < Redcarpet::Render::HTML
include Redcarpet::Render::SmartyPants
def block_code(code, language)
Pygments.highlight(code, lexer: language)
end
def table(header, body)
el('table', el('thead', header) + el('tbody', body), class: 'table table-striped table-bordered')
end
private
def el(el, content, attributes = {})
if content
attrs = attributes ? ' ' + attributes.map { |k,v| "#{k}=\"#{v}\"" }.join(' ') : ''
"<#{el}#{attrs}>\n#{content}</#{el}>\n"
else
''
end
end
end