File tree 3 files changed +27
-6
lines changed
3 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ source 'https://rubygems.org' do
38
38
gem 'omniauth-twitter' , '~> 0.0.16'
39
39
40
40
# Markdown
41
- gem 'redcarpet' #markdown processing
41
+ gem 'redcarpet' , ">=3.3.4"
42
42
gem 'kramdown'
43
43
gem 'github-markdown'
44
44
Original file line number Diff line number Diff line change 503
503
ffi (>= 0.5.0 )
504
504
rdoc (3.12.2 )
505
505
json (~> 1.4 )
506
- redcarpet (3.3.2 )
506
+ redcarpet (3.3.4 )
507
507
redis (3.2.1 )
508
508
redis-actionpack (3.2.4 )
509
509
actionpack (~> 3.2.0 )
@@ -776,7 +776,7 @@ DEPENDENCIES
776
776
rails_12factor !
777
777
rails_latest !
778
778
rakismet !
779
- redcarpet !
779
+ redcarpet ( >= 3.3.4 ) !
780
780
redis-rails (= 3.2.4 )!
781
781
rest-client !
782
782
rspec-rails !
Original file line number Diff line number Diff line change @@ -5,16 +5,37 @@ module CFM
5
5
class Markdown
6
6
class << self
7
7
def render ( text )
8
- renderer = Redcarpet ::Render ::HTML . new
9
- extensions = { fenced_code_blocks : true , strikethrough : true , autolink : true }
8
+ return nil if text . nil?
9
+
10
+ extensions = {
11
+ fenced_code_blocks : true ,
12
+ strikethrough : true ,
13
+ autolink : true
14
+ }
15
+
16
+ renderer = Redcarpet ::Render ::HTML . new ( link_attributes : { rel : "nofollow" } )
10
17
redcarpet = Redcarpet ::Markdown . new ( renderer , extensions )
11
- redcarpet . render ( render_cfm ( text ) ) unless text . nil?
18
+ html = redcarpet . render ( render_cfm ( text ) )
19
+ html = add_nofollow ( html )
20
+ html
12
21
end
13
22
14
23
USERNAME_BLACKLIST = %w( include )
15
24
16
25
private
17
26
27
+ def add_nofollow ( html )
28
+ #redcarpet isn't adding nofollow like it is suppose to.
29
+ html . scan ( /(\< a href=["'].*?["']\> .*?\< \/ a\> )/ ) . flatten . each do |link |
30
+ if link . match ( /\< a href=["'](http:\/ \/ |www){0,1}((coderwall.com)(\/ .*?){0,1}|\/ .*?)["']\> (.*?)\< \/ a\> / )
31
+ else
32
+ link . match ( /(\< a href=["'](.*?)["']\> (.*?)\< \/ a\> )/ )
33
+ html . gsub! ( link , "<a href='#{ $2} ' rel='nofollow' >#{ $3} </a>" )
34
+ end
35
+ end
36
+ html
37
+ end
38
+
18
39
def render_cfm ( text )
19
40
text . lines . map do |x |
20
41
inspect_line ( x )
You can’t perform that action at this time.
0 commit comments