Class: Bypass::HTMLFilter
Constant Summary
Constants inherited
from Filter
Filter::URL_PATTERN
Instance Method Summary
collapse
Methods inherited from Filter
#initialize, #to_s
Constructor Details
This class inherits a constructor from Bypass::Filter
Instance Method Details
#auto_link(options = {}) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/bypass/html_filter.rb', line 15
def auto_link(options = {})
each_text_node do |node|
text = gsub_urls(node.text.to_s) do |url|
build_anchor_tag(url, url, options)
end
node.replace(parse_html_fragment(text))
end
end
|
#build_anchor_tag(text, href, options = {}) ⇒ Object
24
25
26
27
28
|
# File 'lib/bypass/html_filter.rb', line 24
def build_anchor_tag(text, href, options = {})
attributes = []
options.each { |k, v| attributes << " #{k}=\"#{v}\"" }
"<a href=\"#{href}\"#{attributes.join(' ')}>#{text}</a>"
end
|
#content ⇒ Object
30
31
32
|
# File 'lib/bypass/html_filter.rb', line 30
def content
parsed_content.to_s
end
|
#replace(&block) ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'lib/bypass/html_filter.rb', line 6
def replace(&block)
parsed_content.traverse do |node|
if node.name == "a" && href = node.get_attribute("href")
url = yield(Bypass::URI.parse(href))
node.set_attribute("href", url.to_s)
end
end
end
|