fix markdown links that have trailing punctuation inside the url

This commit is contained in:
joshua stein 2012-07-09 18:59:38 -05:00
parent be578454a9
commit f664734a40
2 changed files with 20 additions and 1 deletions

View file

@ -31,6 +31,15 @@ class Comment < ActiveRecord::Base
errors.add(:base, (m[1] == "T" ? "N" : "n") + "ope" + m[2].to_s)
end
def self.regenerate_markdown
Comment.all.each do |c|
c.markeddown_comment = c.generated_markeddown_comment
Comment.record_timestamps = false
c.save(:validate => false)
end
nil
end
def assign_short_id_and_upvote
10.times do |try|
if try == 10

View file

@ -7,7 +7,17 @@ class Markdowner
:filter_styles, :filter_html).to_html
# change <h1> headings to just emphasis tags
html.gsub!(/<(\/)?h(\d)>/) { |_| "<#{$1}strong>" }
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")