From f585d07aa8df25647fc7eb4ed18b25d6d55575b5 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Sat, 23 Mar 2013 21:05:13 -0500 Subject: [PATCH] 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 --- app/models/story.rb | 2 +- app/models/user.rb | 4 +++- extras/markdowner.rb | 48 ++++++++++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/app/models/story.rb b/app/models/story.rb index 5db75f4..31dc86e 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index 04b95c5..4bfde17 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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) diff --git a/extras/markdowner.rb b/extras/markdowner.rb index a5367ea..fa336af 100644 --- a/extras/markdowner.rb +++ b/extras/markdowner.rb @@ -1,28 +1,36 @@ class Markdowner - def self.to_html(text, allow_images = false) + # opts[:allow_images] allows 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

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>/) {|_| - if $2.to_s == $4.to_s - "#{$3}#{$2}" - else - _ - end - } + html = RDiscount.new(text.to_s, *args).to_html - # make links have rel=nofollow - html.gsub!(/ 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>/) {|_| + if $2.to_s == $4.to_s + "#{$3}#{$2}" + else + _ + end + } + + # make links have rel=nofollow + html.gsub!(/