Class | Kramdown::Converter::Base |
In: |
lib/kramdown/converter/base.rb
|
Parent: | Object |
This class serves as base class for all converters. It provides methods that can/should be used by all converters (like generate_id) as well as common functionality that is automatically applied to the result (for example, embedding the output into a template).
A converter object is used as a throw-away object, i.e. it is only used for storing the needed state information during conversion. Therefore one can‘t instantiate a converter object directly but only use the Base::convert method.
Implementing a new converter is rather easy: just derive a new class from this class and put it in the Kramdown::Converter module (the latter is only needed if auto-detection should work properly). Then you need to implement the convert method which has to contain the conversion code for converting an element and has to return the conversion result.
The actual transformation of the document tree can be done in any way. However, writing one method per element type is a straight forward way to do it - this is how the Html and Latex converters do the transformation.
Have a look at the Base::convert method for additional information!
data | [R] | Can be used by a converter for storing arbitrary information during the conversion process. |
options | [R] | The hash with the conversion options. |
root | [R] | The root element that is converted. |
warnings | [R] | The warnings array. |
Convert the element tree tree and return the resulting conversion object (normally a string) and an array with warning messages. The parameter options specifies the conversion options that should be used.
Initializes a new instance of the calling class and then calls the convert method with tree as parameter. If the template option is specified and non-empty, the result is rendered into the specified template. The template resolution is done in the following way:
Convert the element el and return the resulting object.
This is the only method that has to be implemented by sub-classes!
Generate an unique alpha-numeric ID from the the string str for use as a header ID.
Uses the option auto_id_prefix: the value of this option is prepended to every generated ID.