Class: Hexp::Kramdown::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/hexp/kramdown/converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrObject

Returns the value of attribute attr.



5
6
7
# File 'lib/hexp/kramdown/converter.rb', line 5

def attr
  @attr
end

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/hexp/kramdown/converter.rb', line 5

def children
  @children
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/hexp/kramdown/converter.rb', line 5

def options
  @options
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/hexp/kramdown/converter.rb', line 5

def type
  @type
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/hexp/kramdown/converter.rb', line 5

def value
  @value
end

Instance Method Details

#codeblockHexp::Node

Process a Kramdown :codeblock type element

Returns:

  • (Hexp::Node)


49
50
51
# File 'lib/hexp/kramdown/converter.rb', line 49

def codeblock
  H[:pre, attr, H[:code, value]]
end

#codespanObject



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.

Examples:

markdown = "# Hello!\n\nChunky *bacon*!\n"
document = Kramdown::Document.new(markdown)
hexp = converter.convert(document.root)

Parameters:

  • el (Kramdown::Element)

    The root element to convert

Returns:

  • (Hexp::Node)


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.options
  send(type)
end

#convert_childrenArray<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.

Returns:

  • (Array<Hexp::Node>)


123
124
125
# File 'lib/hexp/kramdown/converter.rb', line 123

def convert_children
  children.map {|ch| convert ch }.compact
end

#entityObject



78
79
80
# File 'lib/hexp/kramdown/converter.rb', line 78

def entity
  value.char
end

#headerHexp::Node

Process a Kramdown :header type element

Returns:

  • (Hexp::Node)


40
41
42
# File 'lib/hexp/kramdown/converter.rb', line 40

def header
  tag! "h#{options[:level]}".intern
end

#html_elementObject



74
75
76
# File 'lib/hexp/kramdown/converter.rb', line 74

def html_element
  H[value.to_sym, attr, convert_children]
end

#rootHexp::Node

Process a Kramdown :root type element

Returns:

  • (Hexp::Node)


31
32
33
# File 'lib/hexp/kramdown/converter.rb', line 31

def root
  H[:html, [H[:head], tag!(:body)]]
end

#smart_quoteObject



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.

Parameters:

  • tag (Symbol)

    The HTML tag to generate

Returns:

  • (Hexp::Node)


98
99
100
# File 'lib/hexp/kramdown/converter.rb', line 98

def tag!(tag)
  H[tag, attr, convert_children]
end

#typographic_symObject



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_commentObject



86
# File 'lib/hexp/kramdown/converter.rb', line 86

def xml_comment; end