Sha256: a797703668b092eea3773ad70db135bdd90c180a67a6775efc319a45fd259e60

Contents?: true

Size: 778 Bytes

Versions: 10

Compression:

Stored size: 778 Bytes

Contents

# frozen_string_literal: true
require 'bbcoder'

module HTML
  class Pipeline
    class BbcodeFilter < TextFilter
      def initialize(text, context = {}, result = nil)
        super text, context, result
      end

      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

      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

      def preserve_mkdn_comments(html)
        html.gsub(/^&gt; /, '> ')
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
thredded-0.7.0 lib/html/pipeline/bbcode_filter.rb
thredded-0.6.3 lib/html/pipeline/bbcode_filter.rb
thredded-0.6.2 lib/html/pipeline/bbcode_filter.rb
thredded-0.6.1 lib/html/pipeline/bbcode_filter.rb
thredded-0.6.0 lib/html/pipeline/bbcode_filter.rb
thredded-0.5.1 lib/html/pipeline/bbcode_filter.rb
thredded-0.5.0 lib/html/pipeline/bbcode_filter.rb
thredded-0.4.0 lib/html/pipeline/bbcode_filter.rb
thredded-0.3.2 lib/html/pipeline/bbcode_filter.rb
thredded-0.3.1 lib/html/pipeline/bbcode_filter.rb