require 'redcarpet' require 'rouge' require 'rouge/plugins/redcarpet' module ApplicationHelper class HTML < Redcarpet::Render::HTML include Rouge::Plugins::Redcarpet # yep, that's it. end def title(text) content_for :title, text end def sortable(col, title = nil) title ||= col.titleize css_class = (col == sort_column) ? "current #{sort_direction}" : nil direction = (col == sort_column and sort_direction == "asc") ? "desc" : "asc" link_to title, {:sort => col, :dir => direction}, {:class => css_class} end def markdown(text, params = {}) options = { fenced_code_blocks: true, highlight: true } html_options = {} if params[:restricted] html_options[:filter_html] = true end Redcarpet::Markdown.new(HTML.new(html_options), options).render(text).html_safe end end