Retrospring/app/helpers/markdown_helper.rb

47 lines
1.3 KiB
Ruby
Raw Normal View History

2014-12-28 10:06:49 -08:00
module MarkdownHelper
def markdown(content)
2015-01-12 04:00:00 -08:00
md = Redcarpet::Markdown.new(FlavoredMarkdown, MARKDOWN_OPTS)
Sanitize.fragment(md.render(content), EVIL_TAGS).html_safe
2014-12-28 10:06:49 -08:00
end
2015-01-12 04:00:00 -08:00
def strip_markdown(content)
md = Redcarpet::Markdown.new(Redcarpet::Render::StripDown, MARKDOWN_OPTS)
2015-01-12 04:08:10 -08:00
CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip
2015-01-12 04:00:00 -08:00
end
def twitter_markdown(content)
md = Redcarpet::Markdown.new(TwitteredMarkdown, MARKDOWN_OPTS)
CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip
end
2015-05-24 05:48:54 -07:00
def raw_markdown(content)
2015-05-25 16:26:58 -07:00
md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, RAW_MARKDOWN_OPTS)
2015-05-24 05:48:54 -07:00
raw md.render content
end
def get_markdown(path, relative_to = Rails.root)
begin
File.read relative_to.join(path)
rescue Errno::ENOENT
"# Error reading #{relative_to.join(path)}"
end
end
def markdown_io(path, relative_to = Rails.root)
markdown get_markdown path, relative_to
end
def strip_markdown_io(path, relative_to = Rails.root)
strip_markdown get_markdown path, relative_to
end
def twitter_markdown_io(path, relative_to = Rails.root)
twitter_markdown get_markdown path, relative_to
end
def raw_markdown_io(path, relative_to = Rails.root)
raw_markdown get_markdown path, relative_to
end
end