Class: Slippery::Converter
- Inherits:
-
Object
- Object
- Slippery::Converter
- Defined in:
- lib/slippery/converter.rb
Overview
Main class that does the conversion from Markdown/Kramdown to Hexp. Subclass this for custom behavior.
See github.com/3/blob/master/lib/kramdown/element.rb for a list of types
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 Method Details
#codeblock ⇒ Hexp::Node
Process a Kramdown :codeblock type element
54 55 56 |
# File 'lib/slippery/converter.rb', line 54 def codeblock H[:pre, attr, H[:code, value]] end |
#codespan ⇒ Object
87 88 89 |
# File 'lib/slippery/converter.rb', line 87 def codespan H[:code, value] end |
#convert(el) ⇒ Hexp::Node
Convert a Kramdown syntax tree into Hexp.
24 25 26 27 28 29 |
# File 'lib/slippery/converter.rb', line 24 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.
127 128 129 |
# File 'lib/slippery/converter.rb', line 127 def convert_children children.map {|ch| convert ch }.compact end |
#entity ⇒ Object
83 84 85 |
# File 'lib/slippery/converter.rb', line 83 def entity value.char end |
#header ⇒ Hexp::Node
Process a Kramdown :header type element
45 46 47 |
# File 'lib/slippery/converter.rb', line 45 def header tag! "h#{[:level]}".intern end |
#html_element ⇒ Object
79 80 81 |
# File 'lib/slippery/converter.rb', line 79 def html_element H[value.to_sym, attr, convert_children] end |
#root ⇒ Hexp::Node
Process a Kramdown :root type element
36 37 38 |
# File 'lib/slippery/converter.rb', line 36 def root H[:html, [H[:head], tag!(:body)]] end |
#smart_quote ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/slippery/converter.rb', line 58 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.
103 104 105 |
# File 'lib/slippery/converter.rb', line 103 def tag!(tag) H[tag, attr, convert_children] end |
#typographic_sym ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/slippery/converter.rb', line 67 def typographic_sym { :hellip => '…', :mdash => '—', :ndash => '–', :laquo => '«', :raquo => '»', :laquo_space => '« ', :raquo_space => ' »', }[value] end |
#xml_comment ⇒ Object
91 |
# File 'lib/slippery/converter.rb', line 91 def xml_comment; end |