Class: Kramdown::Converter::Html

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

Overview

Converts a Kramdown::Document to HTML.

You can customize the HTML converter by sub-classing it and overriding the convert_NAME methods. Each such method takes the following parameters:

el

The element of type NAME to 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.

Instance Method Summary collapse

Instance Method Details

#convert_figCaption(el, indent) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/kramdown/converter/bean_html.rb', line 60

def convert_figCaption(el, indent)
  id = ""
  if el.attr['id']
    id = " id=\"#{el.attr['id']}\""
    el.attr['id'] = nil
  end
   "#{' '*indent}<figCaption%s#{html_attributes(el.attr)}>#{escape_html(el.value)}</figCaption>\n" % id
end

#convert_figure(el, indent) ⇒ Object



56
57
58
# File 'lib/kramdown/converter/bean_html.rb', line 56

def convert_figure(el, indent)
  "#{' '*indent}<figure#{html_attributes(el.attr)}>#{inner(el, indent)}</figure>\n"
end

#convert_info_box(el, indent) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kramdown/converter/bean_html.rb', line 21

def convert_info_box(el, indent)
  if el.attr['class']
    el.attr['class'] = el.attr['class'].include?('test') ?
        el.attr['class'] :
        el.attr['class'].split.unshift('test').reject(&:empty?).join(' ')
  else
    el.attr['class'] = 'infoBox'
  end

  "#{' '*indent}<div#{html_attributes(el.attr)}>\n#{inner(el, indent)}#{' '*indent}</div>\n"
end

#convert_oembed(el, indent) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kramdown/converter/bean_html.rb', line 33

def convert_oembed(el, indent)
  provider = el.attr['provider_name']
  el.attr['provider_name'] = nil
  el_id = ""
  if el.attr['html']
    oembed_html = el.attr['html']
    el.attr['html'] = nil
  end
  if el.attr['id']
    el_id = " aria-labelledby=\"#{el.attr['id']}\""
    el.attr['id'] = nil
  end
  if el.attr['role'] === "img"
    "#{' '*indent}<figure%s#{html_attributes(el.attr)}>#{inner(el, indent)}</figure>\n" % el_id
  else
    if provider.casecmp "twitter"
       "#{' '*indent}<figure#{html_attributes(el.attr)}>#{oembed_html}#{inner(el, indent)}</figure>\n"
    else
      "#{' '*indent}<figure%s#{html_attributes(el.attr)}>#{oembed_html}#{inner(el, indent)}</figure>\n" % el_id
    end
  end
end