Sha256: 3987bad02938fc23f280e5c4e0173c6eb129d5c94339f9a77a74963dfa4d59c6

Contents?: true

Size: 650 Bytes

Versions: 1

Compression:

Stored size: 650 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.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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thredded-0.3.0 lib/html/pipeline/bbcode_filter.rb