use a common class for rdiscount options, filter out <h#> tags, add rel=nofollow

This commit is contained in:
joshua stein 2012-07-06 17:52:32 -05:00
parent 9913566b6f
commit c63d35a65d
5 changed files with 22 additions and 8 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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
View 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