Sha256: dc353eabf3ea45d1d39dbb2e5cdb1fb56285fad16709985d7a1705c6f97364ce

Contents?: true

Size: 977 Bytes

Versions: 7

Compression:

Stored size: 977 Bytes

Contents

module Jekyll
  module Converters
    class Markdown
      class RDiscountParser
        def initialize(config)
          Jekyll::Deprecator.gracefully_require "rdiscount"
          @config = config
          @rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym }
        end

        def convert(content)
          rd = RDiscount.new(content, *@rdiscount_extensions)
          html = rd.to_html
          if @config['rdiscount']['toc_token']
            html = replace_generated_toc(rd, html, @config['rdiscount']['toc_token'])
          end
          html
        end

        private
        def replace_generated_toc(rd, html, toc_token)
          if rd.generate_toc && html.include?(toc_token)
            utf8_toc = rd.toc_content
            utf8_toc.force_encoding('utf-8') if utf8_toc.respond_to?(:force_encoding)
            html.gsub(toc_token, utf8_toc)
          else
            html
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jekyll-2.5.3 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.5.2 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.5.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.5.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.4.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.3.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.2.0 lib/jekyll/converters/markdown/rdiscount_parser.rb