Sha256: b9f155c6015e7bc086392007b4efb73146e5f1afc481c935859acf3b1892d760

Contents?: true

Size: 976 Bytes

Versions: 15

Compression:

Stored size: 976 Bytes

Contents

module Jekyll
  module Converters
    class Markdown
      class RDiscountParser
        def initialize(config)
          Jekyll::External.require_with_graceful_fail "rdiscount"
          @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

15 entries across 15 versions & 1 rubygems

Version Path
jekyll-3.5.2 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.5.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.4.5 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.5.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.4.4 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.4.3 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.4.2 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.4.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.4.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.3.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.3.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.3.0.pre.rc1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.2.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.2.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-3.2.0.pre.beta2 lib/jekyll/converters/markdown/rdiscount_parser.rb