Class: Content::Pipeline::Filters::Links
Constant Summary
collapse
- HttpRegexp =
/\A(\/\/|http:\/\/)/
Instance Method Summary
collapse
add_filter, #initialize, #run
Instance Method Details
#external(val) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/content/pipeline/filters/links.rb', line 16
def external(val)
unless !@opts[:host] || val[:href] =~ \
%r!https?://#{Regexp.escape(@opts[:host])}(?:\Z|/)!
val[:target] = "_blank"
end
val
end
|
#https(val) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/content/pipeline/filters/links.rb', line 24
def https(val)
val[:href] = val[:href].gsub(
HttpRegexp, "https://"
)
val
end
|
#wrapper ⇒ Object
7
8
9
10
11
12
13
14
|
# File 'lib/content/pipeline/filters/links.rb', line 7
def wrapper
@str = @str.to_nokogiri_fragment
@str.xpath(".//a").each do |v|
external(https(
v
))
end
end
|