Class: Hexp::Kramdown::Converter
- Inherits:
-
Object
- Object
- Hexp::Kramdown::Converter
- Defined in:
- lib/hexp/kramdown/converter.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#children ⇒ Object
Returns the value of attribute children.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#codeblock ⇒ Hexp::Node
Process a Kramdown :codeblock type element.
- #codespan ⇒ Object
-
#convert(el) ⇒ Hexp::Node
Convert a Kramdown syntax tree into Hexp.
-
#convert_children ⇒ Array<Hexp::Node>
private
Convert the children of the Kramdown element to Hexps.
- #entity ⇒ Object
-
#header ⇒ Hexp::Node
Process a Kramdown :header type element.
- #html_element ⇒ Object
-
#root ⇒ Hexp::Node
Process a Kramdown :root type element.
- #smart_quote ⇒ Object
-
#tag!(tag) ⇒ Hexp::Node
Create a Hexp::Node from the current element.
- #typographic_sym ⇒ Object
- #xml_comment ⇒ Object
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
5 6 7 |
# File 'lib/hexp/kramdown/converter.rb', line 5 def attr @attr end |
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/hexp/kramdown/converter.rb', line 5 def children @children end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/hexp/kramdown/converter.rb', line 5 def @options end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/hexp/kramdown/converter.rb', line 5 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/hexp/kramdown/converter.rb', line 5 def value @value end |
Instance Method Details
#codeblock ⇒ Hexp::Node
Process a Kramdown :codeblock type element
49 50 51 |
# File 'lib/hexp/kramdown/converter.rb', line 49 def codeblock H[:pre, attr, H[:code, value]] end |
#codespan ⇒ Object
82 83 84 |
# File 'lib/hexp/kramdown/converter.rb', line 82 def codespan H[:code, value] end |
#convert(el) ⇒ Hexp::Node
Convert a Kramdown syntax tree into Hexp.
19 20 21 22 23 24 |
# File 'lib/hexp/kramdown/converter.rb', line 19 def convert(el) #Kernel.p el ; exit @type, @value, @attr, @children, @options = el.type, el.value, el.attr, el.children, el. send(type) end |
#convert_children ⇒ Array<Hexp::Node>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convert the children of the Kramdown element to Hexps
In other words, recurse down the tree. This will pass each child element into the converter.
123 124 125 |
# File 'lib/hexp/kramdown/converter.rb', line 123 def convert_children children.map {|ch| convert ch }.compact end |
#entity ⇒ Object
78 79 80 |
# File 'lib/hexp/kramdown/converter.rb', line 78 def entity value.char end |
#header ⇒ Hexp::Node
Process a Kramdown :header type element
40 41 42 |
# File 'lib/hexp/kramdown/converter.rb', line 40 def header tag! "h#{[:level]}".intern end |
#html_element ⇒ Object
74 75 76 |
# File 'lib/hexp/kramdown/converter.rb', line 74 def html_element H[value.to_sym, attr, convert_children] end |
#root ⇒ Hexp::Node
Process a Kramdown :root type element
31 32 33 |
# File 'lib/hexp/kramdown/converter.rb', line 31 def root H[:html, [H[:head], tag!(:body)]] end |
#smart_quote ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/hexp/kramdown/converter.rb', line 53 def smart_quote { :lsquo => '‘', :rsquo => '’', :ldquo => '“', :rdquo => '”', }[value] end |
#tag!(tag) ⇒ Hexp::Node
Create a Hexp::Node from the current element
Helper for when you want to turn the Kramdown element straight into a Hexp::Node with the same attributes, and a one-to-one mapping of the child elements.
98 99 100 |
# File 'lib/hexp/kramdown/converter.rb', line 98 def tag!(tag) H[tag, attr, convert_children] end |
#typographic_sym ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hexp/kramdown/converter.rb', line 62 def typographic_sym { :hellip => '…', :mdash => '—', :ndash => '–', :laquo => '«', :raquo => '»', :laquo_space => '« ', :raquo_space => ' »', }[value] end |
#xml_comment ⇒ Object
86 |
# File 'lib/hexp/kramdown/converter.rb', line 86 def xml_comment; end |