Class: Kramdown::Converter::Bshtml

Inherits:
Html
  • Object
show all
Defined in:
lib/burr/kramdown_ext/converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, options) ⇒ Bshtml

Returns a new instance of Bshtml.



10
11
12
13
# File 'lib/burr/kramdown_ext/converter.rb', line 10

def initialize(root, options)
  super
  @book = options[:register]
end

Instance Attribute Details

#bookObject

Returns the value of attribute book.



8
9
10
# File 'lib/burr/kramdown_ext/converter.rb', line 8

def book
  @book
end

Instance Method Details

#convert_codeblock(el, indent) ⇒ Object

Converts the codeblock to HTML, using pygments to highlight.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/burr/kramdown_ext/converter.rb', line 27

def convert_codeblock(el, indent)
  attr = el.attr.dup
  lang = extract_code_language!(attr)

  caption = attr['caption']
  file    = attr['file']
  code = rouge_highlight(el.value, lang)
  output = '<div class="codeblock'
  output << ' has-caption' if caption
  output << '">'
  if caption
    caption_el = ::Kramdown::Parser::Bsmarkdown.parse(caption).first
    caption_html = inner(caption_el.children.first, 0)
    output << "<p class=\"caption\">#{caption_html}</p>"
  end
  output << "<p class=\"file\"><code>#{file}</code></p>" if file
  output << "#{code}</div>"
end

#convert_footnote(el, indent) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/burr/kramdown_ext/converter.rb', line 66

def convert_footnote(el, indent)
  if self.book.format == 'pdf'
    inline = format_as_span_html('span', { 'class'=> 'footnote', 'id' => "fn-#{ el.options[:name] }"}, inner(el.value, 0))
    inline.sub!(/\s*<p>/, '').sub!(/<\/p>\n/, '')
  else
    number = @footnote_counter
    @footnote_counter += 1
    @footnotes << [el.options[:name], el.value]
    "<sup class=\"footnote\" id=\"fnref-#{el.options[:name]}\"><a href=\"#fn-#{el.options[:name]}\" rel=\"footnote\">#{number}</a></sup>"
  end
end

#convert_header(el, indent) ⇒ Object

Converts headers



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/burr/kramdown_ext/converter.rb', line 48

def convert_header(el, indent)
  attr = el.attr.dup
  item = self.book.current_item
  if @options[:auto_ids] && !attr['id']
    attr['id'] = generate_id(el.options[:raw_text])
  end
  #@toc << [el.options[:level], attr['id'], el.children] if attr['id'] && in_toc?(el)
  unless attr['class'] == 'skip-toc'
    item['toc'] << {
      'level' => el.options[:level],
      'title' => el.options[:raw_text]
    }
  end

  level = output_header_level(el.options[:level])
  format_as_block_html("h#{level}", attr, inner(el, indent), indent)
end

#convert_p(el, indent) ⇒ Object

Converts paragraph contents image with caption and normal paragraph.



17
18
19
20
21
22
23
# File 'lib/burr/kramdown_ext/converter.rb', line 17

def convert_p(el, indent)
  if el.children.size == 1 && el.children.first.type == :img && !el.children.first.attr['caption'].nil?
    convert_image_with_caption(el, indent)
  else
    super
  end
end

#convert_table(el, indent) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/burr/kramdown_ext/converter.rb', line 91

def convert_table(el, indent)
  caption = el.attr.delete('caption')
  output = '<div class="table'
  if caption
    caption_el = ::Kramdown::Parser::Bsmarkdown.parse(caption).first
    caption_html = inner(caption_el.children.first, 0)
    output << " has-caption\"><p class=\"caption\">#{caption_html}</p>"
  else
    output << '">'
  end
  output << format_as_indented_block_html(el.type, el.attr, inner(el, indent), indent)
  output << '</div>'
end

#footnote_contentObject

Return a HTML ordered list with the footnote content for the used footnotes.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/burr/kramdown_ext/converter.rb', line 106

def footnote_content
  ol = Element.new(:ol)
  ol.attr['start'] = @footnote_start if @footnote_start != 1
  @footnotes.each do |name, data|
    li = Element.new(:li, nil, {'id' => "fn-#{name}"})
    li.children = Marshal.load(Marshal.dump(data.children))
    ol.children << li

    ref = Element.new(:raw, "<a href=\"#fnref-#{name}\" rel=\"reference\">&#8617;</a>")
    if li.children.last.type == :p
      para = li.children.last
    else
      li.children << (para = Element.new(:p))
    end
    para.children << ref
  end
  (ol.children.empty? ? '' : format_as_indented_block_html('div', {:class => "footnotes"}, convert(ol, 2), 0))
end

#orin_convert_tableObject Also known as: convert_thead, convert_tbody, convert_tfoot, convert_tr



84
# File 'lib/burr/kramdown_ext/converter.rb', line 84

alias :orin_convert_table :convert_table