# We define the an additional option for the kramdown parser to look for module Kramdown module Options define(:kramdown_default_lang, Symbol, nil, <#{code}\n" end def convert_codespan(el, indent) attr = el.attr.dup lang = extract_code_language_with_fix!(attr) code = pygmentize(el.value, lang) if lang attr['class'] = "highlight" if attr.has_key?('class') attr['class'] += " language-#{lang}" else attr['class'] = "language-#{lang}" end end "#{code}" end def pygmentize(code, lang) if lang Pygments.highlight(code, :lexer => lang, :options => { :startinline => true, :encoding => 'utf-8', :nowrap => true }) else escape_html(code) end end end end end # This class is the actual custom Jekyll converter. class Jekyll::Converters::Markdown::KramdownPygments def initialize(config) require 'kramdown' @config = config rescue LoadError STDERR.puts 'You are missing a library required for Markdown. Please run:' STDERR.puts ' $ [sudo] gem install kramdown' raise FatalException.new("Missing dependency: kramdown") end def convert(content) html = Kramdown::Document.new(content, { :auto_ids => @config['kramdown']['auto_ids'], :footnote_nr => @config['kramdown']['footnote_nr'], :entity_output => @config['kramdown']['entity_output'], :toc_levels => @config['kramdown']['toc_levels'], :smart_quotes => @config['kramdown']['smart_quotes'], :kramdown_default_lang => @config['kramdown']['default_lang'], :input => @config['kramdown']['input'] }).to_pygments_html return html; end end