Add a simple "text" format to the RichText module
This commit is contained in:
parent
6039aac76e
commit
98592e2903
1 changed files with 23 additions and 8 deletions
|
@ -3,6 +3,7 @@ module RichText
|
||||||
case format
|
case format
|
||||||
when "html"; HTML.new(text || "")
|
when "html"; HTML.new(text || "")
|
||||||
when "markdown"; Markdown.new(text || "")
|
when "markdown"; Markdown.new(text || "")
|
||||||
|
when "text"; Text.new(text || "")
|
||||||
else; nil
|
else; nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,6 +28,16 @@ module RichText
|
||||||
|
|
||||||
return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20
|
return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def linkify(text)
|
||||||
|
if text.html_safe?
|
||||||
|
Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
|
||||||
|
else
|
||||||
|
Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class HTML < Base
|
class HTML < Base
|
||||||
|
@ -46,14 +57,6 @@ module RichText
|
||||||
def sanitize(text)
|
def sanitize(text)
|
||||||
Sanitize.clean(text, Sanitize::Config::OSM).html_safe
|
Sanitize.clean(text, Sanitize::Config::OSM).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def linkify(text)
|
|
||||||
if text.html_safe?
|
|
||||||
Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
|
|
||||||
else
|
|
||||||
Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Markdown < Base
|
class Markdown < Base
|
||||||
|
@ -76,4 +79,16 @@ module RichText
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Text < Base
|
||||||
|
include ActionView::Helpers::TextHelper
|
||||||
|
|
||||||
|
def to_html
|
||||||
|
linkify(simple_format(ERB::Util.html_escape(self)))
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_text
|
||||||
|
self
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue