Class: Slippery::Converter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrObject

Returns the value of attribute attr.



11
12
13
# File 'lib/slippery/converter.rb', line 11

def attr
  @attr
end

#childrenObject

Returns the value of attribute children.



11
12
13
# File 'lib/slippery/converter.rb', line 11

def children
  @children
end

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/slippery/converter.rb', line 11

def options
  @options
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/slippery/converter.rb', line 11

def type
  @type
end

#valueObject

Returns the value of attribute value.



11
12
13
# File 'lib/slippery/converter.rb', line 11

def value
  @value
end

Instance Method Details

#codeblockHexp::Node

Process a Kramdown :codeblock type element

Returns:

  • (Hexp::Node)


55
56
57
# File 'lib/slippery/converter.rb', line 55

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

#codespanObject



88
89
90
# File 'lib/slippery/converter.rb', line 88

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)


25
26
27
28
29
30
# File 'lib/slippery/converter.rb', line 25

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>)


128
129
130
# File 'lib/slippery/converter.rb', line 128

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

#entityObject



84
85
86
# File 'lib/slippery/converter.rb', line 84

def entity
  value.char
end

#headerHexp::Node

Process a Kramdown :header type element

Returns:

  • (Hexp::Node)


46
47
48
# File 'lib/slippery/converter.rb', line 46

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

#html_elementObject



80
81
82
# File 'lib/slippery/converter.rb', line 80

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

#rootHexp::Node

Process a Kramdown :root type element

Returns:

  • (Hexp::Node)


37
38
39
# File 'lib/slippery/converter.rb', line 37

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

#smart_quoteObject



59
60
61
62
63
64
65
66
# File 'lib/slippery/converter.rb', line 59

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)


104
105
106
# File 'lib/slippery/converter.rb', line 104

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

#typographic_symObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/slippery/converter.rb', line 68

def typographic_sym
  {
    :hellip => '',
    :mdash  => '',
    :ndash  => '',
    :laquo  => '«',
    :raquo  => '»',
    :laquo_space => '« ',
    :raquo_space => ' »',
  }[value]
end

#xml_commentObject



92
# File 'lib/slippery/converter.rb', line 92

def xml_comment; end