Class: Thredded::BBCode::Filter
- Inherits:
-
HTML::Pipeline::TextFilter
- Object
- HTML::Pipeline::TextFilter
- Thredded::BBCode::Filter
- Defined in:
- lib/thredded/bbcode/filter.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(text, context = {}, result = nil) ⇒ Filter
constructor
A new instance of Filter.
-
#remove_url_link_contents!(html) ⇒ Object
<a href=“example.com”>example.com</a> => <a href=“example.com”>example.com</a>.
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
#call ⇒ Object
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 |
#remove_url_link_contents!(html) ⇒ Object
<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 |