use a common class for rdiscount options, filter out <h#> tags, add rel=nofollow
This commit is contained in:
parent
9913566b6f
commit
c63d35a65d
|
@ -117,8 +117,7 @@ class Comment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def generated_markeddown_comment
|
||||
RDiscount.new(self.comment, :smart, :autolink, :safelink,
|
||||
:filter_html).to_html
|
||||
Markdowner.to_html(self.comment)
|
||||
end
|
||||
|
||||
def comment=(com)
|
||||
|
|
|
@ -78,8 +78,7 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def linkified_body
|
||||
RDiscount.new(self.body.to_s, :smart, :autolink, :safelink,
|
||||
:filter_html).to_html
|
||||
Markdowner.to_html(self.body)
|
||||
end
|
||||
|
||||
def plaintext_body
|
||||
|
|
|
@ -157,8 +157,7 @@ class Story < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def generated_markeddown_description
|
||||
RDiscount.new(self.description.to_s, :smart, :autolink, :safelink,
|
||||
:filter_html).to_html
|
||||
Markdowner.to_html(self.description)
|
||||
end
|
||||
|
||||
def description=(desc)
|
||||
|
|
|
@ -62,8 +62,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def linkified_about
|
||||
RDiscount.new(self.about.to_s, :smart, :autolink, :safelink,
|
||||
:filter_html).to_html
|
||||
Markdowner.to_html(self.about)
|
||||
end
|
||||
|
||||
def recent_threads(amount)
|
||||
|
|
18
extras/markdowner.rb
Normal file
18
extras/markdowner.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
class Markdowner
|
||||
def self.to_html(text)
|
||||
if text.blank?
|
||||
return ""
|
||||
else
|
||||
html = RDiscount.new(text.to_s, :smart, :autolink, :safelink,
|
||||
:filter_styles, :filter_html).to_html
|
||||
|
||||
# change <h1> headings to just emphasis tags
|
||||
html.gsub!(/<(\/)?h(\d)>/) { |_| "<#{$1}strong>" }
|
||||
|
||||
# make links have rel=nofollow
|
||||
html.gsub!(/<a href/, "<a rel=\"nofollow\" href")
|
||||
|
||||
html
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue