Class: HTML::Pipeline::BbcodeFilter

Inherits:
TextFilter
  • Object
show all
Defined in:
lib/html/pipeline/bbcode_filter.rb

Instance Method Summary collapse

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

#callObject



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(/^&gt; /, '> ')
end


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