Class: Thredded::BBCode::Filter

Inherits:
HTML::Pipeline::TextFilter
  • Object
show all
Defined in:
lib/thredded/bbcode/filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(text, context = {}, result = nil) ⇒ Filter

Returns a new instance of Filter.



10
11
12
# File 'lib/thredded/bbcode/filter.rb', line 10

def initialize(text, context = {}, result = nil)
  super text, context, result
end

Instance Method Details

#callObject



14
15
16
17
18
19
# File 'lib/thredded/bbcode/filter.rb', line 14

def call
  html = BBCoder.new(@text).to_html
  remove_url_link_contents! html
  html.rstrip!
  html
end

<a href=“example.com”>example.com</a> => <a href=“example.com”>example.com</a>



23
24
25
26
27
# File 'lib/thredded/bbcode/filter.rb', line 23

def remove_url_link_contents!(html)
  # The doc is not fully HTML yet (it will still be parsed with markdown),
  # so we can't use Nokogiri to process it here.
  html.gsub!(%r{(<a href="[^"]*"[^>]*>)https?://(.*?</a>)}m, '\1\2')
end