Class: Kramdown::Converter::Bshtml
- Defined in:
- lib/burr/kramdown_ext/converter.rb
Instance Attribute Summary collapse
-
#book ⇒ Object
Returns the value of attribute book.
Instance Method Summary collapse
-
#convert_codeblock(el, indent) ⇒ Object
Converts the codeblock to HTML, using pygments to highlight.
- #convert_footnote(el, indent) ⇒ Object
-
#convert_header(el, indent) ⇒ Object
Converts headers.
-
#convert_p(el, indent) ⇒ Object
Converts paragraph contents image with caption and normal paragraph.
- #convert_table(el, indent) ⇒ Object
-
#footnote_content ⇒ Object
Return a HTML ordered list with the footnote content for the used footnotes.
-
#initialize(root, options) ⇒ Bshtml
constructor
A new instance of Bshtml.
- #orin_convert_table ⇒ Object (also: #convert_thead, #convert_tbody, #convert_tfoot, #convert_tr)
Constructor Details
Instance Attribute Details
#book ⇒ Object
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) = attr['caption'] file = attr['file'] code = rouge_highlight(el.value, lang) output = '<div class="codeblock' output << ' has-caption' if output << '">' if = ::Kramdown::Parser::Bsmarkdown.parse().first = inner(.children.first, 0) output << "<p class=\"caption\">#{}</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.[:name] }"}, inner(el.value, 0)) inline.sub!(/\s*<p>/, '').sub!(/<\/p>\n/, '') else number = @footnote_counter @footnote_counter += 1 @footnotes << [el.[:name], el.value] "<sup class=\"footnote\" id=\"fnref-#{el.[:name]}\"><a href=\"#fn-#{el.[: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.[: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.[:level], 'title' => el.[:raw_text] } end level = output_header_level(el.[: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? (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) = el.attr.delete('caption') output = '<div class="table' if = ::Kramdown::Parser::Bsmarkdown.parse().first = inner(.children.first, 0) output << " has-caption\"><p class=\"caption\">#{}</p>" else output << '">' end output << format_as_indented_block_html(el.type, el.attr, inner(el, indent), indent) output << '</div>' end |
#footnote_content ⇒ Object
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\">↩</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_table ⇒ Object 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 |