- def html_parser
- @@html_renderer ||= Redcarpet::Render::XHTML.new({
- :filter_html => true, :safe_links_only => true
- })
- @@html_parser ||= Redcarpet::Markdown.new(@@html_renderer, {
- :no_intra_emphasis => true, :autolink => true, :space_after_headers => true
- })
+ def sanitize(text)
+ Sanitize.clean(text, Sanitize::Config::OSM).html_safe
+ end
+ end
+
+ class Markdown < Base
+ def to_html
+ Markdown.html_parser.render(self).html_safe
+ end
+
+ def to_text
+ to_s
+ end
+
+ def self.html_renderer
+ @html_renderer ||= Renderer.new(:filter_html => true, :safe_links_only => true)
+ end
+
+ def self.html_parser
+ @html_parser ||= Redcarpet::Markdown.new(html_renderer, :no_intra_emphasis => true, :autolink => true, :space_after_headers => true)
+ end
+
+ class Renderer < Redcarpet::Render::XHTML
+ def link(link, _title, alt_text)
+ "<a rel=\"nofollow\" href=\"#{link}\">#{alt_text}</a>"
+ end
+
+ def autolink(link, link_type)
+ if link_type == :email
+ "<a rel=\"nofollow\" href=\"mailto:#{link}\">#{link}</a>"
+ else
+ "<a rel=\"nofollow\" href=\"#{link}\">#{link}</a>"
+ end
+ end
+ end
+ end
+
+ class Text < Base
+ def to_html
+ linkify(simple_format(ERB::Util.html_escape(self)))
+ end
+
+ def to_text
+ to_s