Allow loading markdown files from FS
This commit is contained in:
parent
49dea9095a
commit
9d93bbf9b1
|
@ -14,4 +14,33 @@ module MarkdownHelper
|
||||||
md = Redcarpet::Markdown.new(TwitteredMarkdown, MARKDOWN_OPTS)
|
md = Redcarpet::Markdown.new(TwitteredMarkdown, MARKDOWN_OPTS)
|
||||||
CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip
|
CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
def raw_markdown(content)
|
||||||
|
md = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue