Class: Kramdown::Converter::Ascii
- Inherits:
-
Base
- Object
- Base
- Kramdown::Converter::Ascii
- Includes:
- Parser::Html::Constants, Utils::Html
- Defined in:
- lib/jay_flavored_markdown/markdown_to_ascii.rb
Overview
Converts a Kramdown::Document to ASCII Plain Text.
You can customize this converter by sub-classing it and overriding the convert_NAME methods. Each such method takes the following parameters:
el-
The element of type
NAMEto be converted. indent-
A number representing the current amount of spaces for indent (only used for block-level elements).
The return value of such a method has to be a string containing the element el formatted as HTML element.
Constant Summary collapse
- MAX_COLUMN =
80- DISPATCHER =
The mapping of element type to conversion method.
Hash.new {|h,k| h[k] = "convert_#{k}"}
Instance Attribute Summary collapse
-
#indent ⇒ Object
The amount of indentation used when nesting HTML tags.
Instance Method Summary collapse
-
#convert(el, indent = 0) ⇒ Object
Dispatch the conversion of the element
elto aconvert_TYPEmethod using thetypeof the element. -
#initialize(root, options) ⇒ Ascii
constructor
Initialize the ASCII converter with the given Kramdown document
doc.
Constructor Details
#initialize(root, options) ⇒ Ascii
Initialize the ASCII converter with the given Kramdown document doc.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jay_flavored_markdown/markdown_to_ascii.rb', line 61 def initialize(root, ) super @indent = 2 @stack = [] @xref_table = {} ref_visitor = ReferenceVisitor.new @root = ref_visitor.traverse(@root) @xref_table = ref_visitor.xref_table @item_table = ref_visitor.item_table @section_table = ref_visitor.section_table debug_dump_tree(@root) if $JAY_DEBUG @root end |
Instance Attribute Details
#indent ⇒ Object
The amount of indentation used when nesting HTML tags.
58 59 60 |
# File 'lib/jay_flavored_markdown/markdown_to_ascii.rb', line 58 def indent @indent end |
Instance Method Details
#convert(el, indent = 0) ⇒ Object
Dispatch the conversion of the element el to a convert_TYPE method using the type of the element.
77 78 79 |
# File 'lib/jay_flavored_markdown/markdown_to_ascii.rb', line 77 def convert(el, indent = 0) send(DISPATCHER[el.type], el, indent) end |