Sha256: d2729c5fd92a004af763cd2588c10a167a5d3693b28d5f2618b522267ae613d0

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Jekyll
  module Converters
    class Markdown
      class RDiscountParser
        def initialize(config)
          unless defined?(RDiscount)
            Jekyll::External.require_with_graceful_fail "rdiscount"
          end
          @config = config
          @rdiscount_extensions = @config["rdiscount"]["extensions"].map(&: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

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-3.7.4 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.8.0.pre.rc1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.7.3 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.7.2 lib/jekyll/converters/markdown/rdiscount_parser.rb