Sha256: 5f4de2ad1ac09039ba070098ec67988365c1bb7021b9eac2ba6c6c8c091b0b48

Contents?: true

Size: 698 Bytes

Versions: 9

Compression:

Stored size: 698 Bytes

Contents

require 'coderay'
require 'htmlentities'

module Thredded
  module Filter
    module Syntax
      def filtered_content
        content = String.new(super)
        content = HTMLEntities.new.decode(content)

        content = content.to_s
          .gsub(/\<pre\>\<code( lang="(.+?)")?\>(.+?)\<\/code\>\<\/pre\>/m) do
          filter = $2.nil? ? :ruby : $2.to_sym
          temp_code = $3.gsub(/&quot;/, '"').
            gsub(/&#39;/,"'").
            gsub(/&amp;/, "&").
            gsub(/&gt;/, ">").
            gsub(/&lt;/, "<").
            gsub(/\<br \/\>/, "")

          ::CodeRay.scan(temp_code, filter).div(css: :class)
        end

        content.html_safe
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
thredded-0.0.10 lib/thredded/filter/syntax.rb
thredded-0.0.9 lib/thredded/filter/syntax.rb
thredded-0.0.8 lib/thredded/filter/syntax.rb
thredded-0.0.7 lib/thredded/filter/syntax.rb
thredded-0.0.6 lib/thredded/filter/syntax.rb
thredded-0.0.5 lib/thredded/filter/syntax.rb
thredded-0.0.4 lib/thredded/filter/syntax.rb
thredded-0.0.3 lib/thredded/filter/syntax.rb
thredded-0.0.1 lib/thredded/filter/syntax.rb