Sha256: e2f7ed11b8dd815540a16a59c414749d3df2f0d5fb865fb8f40bc547f7729b18

Contents?: true

Size: 1.15 KB

Versions: 22

Compression:

Stored size: 1.15 KB

Contents

module Jekyll
  module Converters
    class Markdown
      class RDiscountParser
        def initialize(config)
          require 'rdiscount'
          @config = config
          @rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym }
        rescue LoadError
          STDERR.puts 'You are missing a library required for Markdown. Please run:'
          STDERR.puts '  $ [sudo] gem install rdiscount'
          raise FatalException.new("Missing dependency: rdiscount")
        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

22 entries across 22 versions & 2 rubygems

Version Path
jekyll-2.1.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.1.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.0.3 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.0.2 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.0.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.0.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.0.0.rc1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.0.0.alpha.3 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.5.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.0.0.alpha.2 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.5.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-2.0.0.alpha.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.4.3 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.4.2 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.4.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.4.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.3.1 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.3.0 lib/jekyll/converters/markdown/rdiscount_parser.rb
jekyll-1.3.0.rc lib/jekyll/converters/markdown/rdiscount_parser.rb
monad-0.0.3 lib/jekyll/converters/markdown/rdiscount_parser.rb