Class | Kramdown::Parser::Base |
In: |
lib/kramdown/parser/base.rb
|
Parent: | Object |
This class serves as base class for parsers. It provides common methods that can/should be used by all parsers, especially by those using StringScanner for parsing.
A parser object is used as a throw-away object, i.e. it is only used for storing the needed state information during parsing. Therefore one can‘t instantiate a parser object directly but only use the Base::parse method.
Implementing a new parser is rather easy: just derive a new class from this class and put it in the Kramdown::Parser module — the latter is needed so that the auto-detection of the new parser works correctly. Then you need to implement the +parse+ method which has to contain the parsing code.
Have a look at the Base::parse, Base::new and Base#parse methods for additional information!
options | [R] | The hash with the parsing options. |
root | [R] | The root element of element tree that is created from the source string. |
source | [R] | The original source string. |
warnings | [R] | The array with the parser warnings. |
Modify the string source to be usable by the parser (unifies line ending characters to +\n+ and makes sure source ends with a new line character).
This helper method adds the given text either to the last element in the tree if it is a type element or creates a new text element with the given type.
Extract the part of the StringScanner strscan backed string specified by the range. This method works correctly under Ruby 1.8 and Ruby 1.9.
Parse the source string into an element tree.
The parsing code should parse the source provided in @source and build an element tree the root of which should be @root.
This is the only method that has to be implemented by sub-classes!