class Kramdown::JekyllDocument
converting all Markdown documents in a Jekyll site.
The optimization is by using the same options Hash (and its derivatives) for
a kramdown document for parsing.
A Kramdown::Document subclass meant to optimize memory usage from initializing
def initialize(source, options = {})
def initialize(source, options = {}) JekyllDocument.setup(options) @options = JekyllDocument.options @root, @warnings = JekyllDocument.parser.parse(source, @options) end
def setup(options)
The implementation is basically the core logic in +Kramdown::Document#initialize+
def setup(options) @cache ||= {} # reset variables on a subsequent set up with a different options Hash unless @cache[:id] == options.hash @options = @parser = nil @cache[:id] = options.hash end @options ||= Options.merge(options).freeze @parser ||= begin parser_name = (@options[:input] || "kramdown").to_s parser_name = parser_name[0..0].upcase + parser_name[1..-1] try_require("parser", parser_name) if Parser.const_defined?(parser_name) Parser.const_get(parser_name) else raise Kramdown::Error, "kramdown has no parser to handle the specified " \ "input format: #{@options[:input]}" end end end
def to_html
The implementation is basically an optimized version of core logic in
Use Kramdown::Converter::Html class to convert this document into HTML.
def to_html output, warnings = Kramdown::Converter::Html.convert(@root, @options) @warnings.concat(warnings) output end
def try_require(type, name)
def try_require(type, name) require "kramdown/#{type}/#{Utils.snake_case(name)}" rescue LoadError false end