class Kramdown::Document
Re-open class Document
The main interface to kramdown-respec.
This class provides a one-stop-shop for using kramdown-respec to convert text into various output formats. Use it like this:
require 'kramdown-respec' doc = KramdownRespec::Document.new('This *is* some kramdown-respec text') puts doc.to_html
The to_html method is a shortcut for using the Converter::Html
class. See method_missing for more information.
The second argument to the ::new
method is an options hash for customizing the behaviour of the used parser and the converter. See ::new
for more information!
Public Class Methods
Redfine method initialize()
Create a new KramdownRespec document from the string source
and use the provided options
. The options that can be used are defined in the Options module.
The special options key :input can be used to select the parser that should parse the source
. It has to be the name of a class in the KramdownRespec::Parser module. For example, to select the kramdown-respec parser, one would set the :input key to KramdownRespec
. If this key is not set, it defaults to KramdownRespec
.
The source
is immediately parsed by the selected parser so that the root element is immediately available and the output can be generated.
# File lib/kramdown-respec.rb, line 51 def initialize(source, options = {}) @options = Options.merge(options).freeze # parser = (@options[:input] || 'kramdown-respec').to_s parser = (@options[:input] || 'kramdown').to_s parser = parser[0..0].upcase + parser[1..-1] try_require('parser', parser) if Parser.const_defined?(parser) @root, @warnings = Parser.const_get(parser).parse(source, @options) else raise Kramdown::Error.new("kramdown-respec has no parser to handle the specified input format: #{@options[:input]}") end end