Class: HTML::Pipeline::BbcodeFilter
- Inherits:
-
TextFilter
- Object
- TextFilter
- HTML::Pipeline::BbcodeFilter
- Defined in:
- lib/html/pipeline/bbcode_filter.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(text, context = {}, result = nil) ⇒ BbcodeFilter
constructor
A new instance of BbcodeFilter.
- #preserve_mkdn_comments(html) ⇒ Object
- #remove_url_link_contents(html) ⇒ Object
Constructor Details
#initialize(text, context = {}, result = nil) ⇒ BbcodeFilter
Returns a new instance of BbcodeFilter.
7 8 9 |
# File 'lib/html/pipeline/bbcode_filter.rb', line 7 def initialize(text, context = {}, result = nil) super text, context, result end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/html/pipeline/bbcode_filter.rb', line 11 def call html = BBCoder.new(@text).to_html html = remove_url_link_contents(html) html = preserve_mkdn_comments(html) html.delete('<br>') html.rstrip! html end |
#preserve_mkdn_comments(html) ⇒ Object
28 29 30 |
# File 'lib/html/pipeline/bbcode_filter.rb', line 28 def preserve_mkdn_comments(html) html.gsub(/^> /, '> ') end |
#remove_url_link_contents(html) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/html/pipeline/bbcode_filter.rb', line 20 def remove_url_link_contents(html) doc = Nokogiri::HTML::DocumentFragment.parse(html) doc.css('a').each do |link| link.content = link.content.gsub(%r{https?://}, '') end doc.to_html end |