don't do @username expansion in user profile about section

most users are probably putting @username to mean a twitter profile,
not a link to a lobste.rs profile
This commit is contained in:
joshua stein 2013-03-23 21:05:13 -05:00
parent e8bb03a689
commit f585d07aa8
3 changed files with 32 additions and 22 deletions

View file

@ -267,7 +267,7 @@ class Story < ActiveRecord::Base
end
def generated_markeddown_description
Markdowner.to_html(self.description, allow_images = true)
Markdowner.to_html(self.description, { :allow_images => true })
end
def description=(desc)

View file

@ -116,7 +116,9 @@ class User < ActiveRecord::Base
end
def linkified_about
Markdowner.to_html(self.about)
# most users are probably mentioning "@username" to mean a twitter url, not
# a link to a lobste.rs profile
Markdowner.to_html(self.about, { :disable_profile_links => true })
end
def recent_threads(amount)

View file

@ -1,28 +1,36 @@
class Markdowner
def self.to_html(text, allow_images = false)
# opts[:allow_images] allows <img> tags
# opts[:disable_profile_links] disables @username -> /u/username links
def self.to_html(text, opts = {})
if text.blank?
return ""
else
html = RDiscount.new(text.to_s, *[ :smart, :autolink, :safelink,
:filter_styles, :filter_html ] + (allow_images ? [] : [ :no_image ])).
to_html
end
# change <h1> headings to just emphasis tags
html.gsub!(/<(\/)?h(\d)>/) {|_| "<#{$1}strong>" }
args = [ :smart, :autolink, :safelink, :filter_styles, :filter_html ]
if !opts[:allow_images]
args.push :no_image
end
# fix links that got the trailing punctuation appended to move it outside
# the link
html.gsub!(/<a ([^>]+)([\.\!\,])">([^>]+)([\.\!\,])<\/a>/) {|_|
if $2.to_s == $4.to_s
"<a #{$1}\">#{$3}</a>#{$2}"
else
_
end
}
html = RDiscount.new(text.to_s, *args).to_html
# make links have rel=nofollow
html.gsub!(/<a href/, "<a rel=\"nofollow\" href")
# change <h1> headings to just emphasis tags
html.gsub!(/<(\/)?h(\d)>/) {|_| "<#{$1}strong>" }
# fix links that got the trailing punctuation appended to move it outside
# the link
html.gsub!(/<a ([^>]+)([\.\!\,])">([^>]+)([\.\!\,])<\/a>/) {|_|
if $2.to_s == $4.to_s
"<a #{$1}\">#{$3}</a>#{$2}"
else
_
end
}
# make links have rel=nofollow
html.gsub!(/<a href/, "<a rel=\"nofollow\" href")
if !opts[:disable_profile_links]
# make @username link to that user's profile
html.gsub!(/\B\@([\w\-]+)/) do |u|
if User.find_by_username(u[1 .. -1])
@ -31,8 +39,8 @@ class Markdowner
u
end
end
html
end
html
end
end