class Rabbit::Parser::Markdown::Converter
Public Class Methods
new(canvas)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 7 def initialize(canvas) @canvas = canvas @slides = [] @slide = nil @slide_property_mode = false end
Public Instance Methods
convert(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 14 def convert(element) __send__("convert_#{element.type}", element) end
Private Instance Methods
convert_a(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 255 def convert_a(element) ref = ReferText.new(convert_container(element)) ref.to = element.attr['href'] ref end
convert_blank(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 97 def convert_blank(element) :no_element end
convert_blockquote(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 210 def convert_blockquote(element) BlockQuote.new(convert_container(element)) end
convert_codeblock(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 200 def convert_codeblock(element) content = element.value.chomp lang = element.attr["lang"] if lang highlighted = Ext::CodeRay.highlight(lang, content, @canvas.logger) return highlighted if highlighted end PreformattedBlock.new(PreformattedText.new(text(content))) end
convert_comment(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 196 def convert_comment(element) :no_element end
convert_container(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 19 def convert_container(element) elements = [] element.children.each do |child| element = convert(child) case element when nil, :no_element # ignore else elements << element end end elements end
convert_dd(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 122 def convert_dd(element) DescriptionContent.new(convert_container(element)) end
convert_dl(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 101 def convert_dl(element) list = DescriptionList.new term = nil content = nil convert_container(element).each do |item| case item when DescriptionTerm list << DescriptionListItem.new(term, content) if term term = item when DescriptionContent content = item end end list << DescriptionListItem.new(term, content) if term list end
convert_dt(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 118 def convert_dt(element) DescriptionTerm.new(Paragraph.new(convert_container(element))) end
convert_em(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 240 def convert_em(element) Emphasis.new(Emphasis.new(convert_container(element))) end
convert_header(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 65 def convert_header(element) slide, @slide = @slide, nil contents = convert_container(element) case element.options[:level] when 1 if @slides.empty? @slide = TitleSlide.new(Title.new(contents)) else @slide = Slide.new(HeadLine.new(contents)) @slide << Body.new end @slides << @slide @slide when 2 if /\Anote\z/i =~ contents.first.text NoteSetter.new(@slides.last) else SlidePropertySetter.new(@slides.last) end else nil end end
convert_img(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 214 def convert_img(element) options = element.attr.dup uri = options.delete("src") title = options.delete("title") alt = options.delete("alt") caption = title || alt options["caption"] ||= caption if caption if options["align"] == "right" body = @slides.last.body if body["background-image"] raise ParseError, _("multiple {:align='right'} " + "isn't supported.") end body["background-image"] = uri options.each do |name, value| name = name.to_s.gsub(/_/, '-') body["background-image-#{name}"] = value end :no_element else image = Ext::Image.make_image(@canvas, uri, options) image || text(alt || src) end end
convert_li(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 143 def convert_li(element) ItemListItem.new(convert_container(element)) end
convert_math(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 248 def convert_math(element) args = [@canvas, element.value] Ext::Image.make_image_from_file(*args) do |src_file_path| [Ext::TeX.make_image_by_LaTeX(src_file_path, {}, @canvas), {}] end end
convert_p(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 126 def convert_p(element) if element.children.collect {|child| child.type} == [:img] convert_container(element)[0] else if element.children.any? {|child| child.type == :img} raise ParseError, _("multiple ![alt]{image} in a paragraph isn't supported.") else Paragraph.new(convert_container(element)) end end end
convert_root(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 33 def convert_root(element) target = nil mode = :ignore require 'pp' convert_container(element).each do |content| case content when :no_element next when nil mode = :ignore when Slide target = content.body @canvas << content mode = :display when TitleSlide target = content @canvas << content mode = :display when SlidePropertySetter, NoteSetter target = content mode = :property else case mode when :display target << content when :property target.apply(content) end end end end
convert_smart_quote(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 147 def convert_smart_quote(element) Text.new(Parser::Ext::Entity::TABLE[element.value.to_s]) end
convert_strong(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 244 def convert_strong(element) Emphasis.new(Emphasis.new(convert_container(element))) end
convert_table(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 155 def convert_table(element) table = Table.new convert_container(element).each do |item| table << item end table end
convert_tbody(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 176 def convert_tbody(element) TableBody.new(convert_container(element)) end
convert_td(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 184 def convert_td(element) if @in_table_header header = TableHeader.new(convert_container(element)) def header.default_align Pango::Layout::ALIGN_CENTER end header else TableCell.new(convert_container(element)) end end
convert_text(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 93 def convert_text(element) text(element.value) end
convert_thead(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 163 def convert_thead(element) in_table_header do TableHead.new(convert_container(element)) end end
convert_tr(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 180 def convert_tr(element) TableRow.new(convert_container(element)) end
convert_typographic_sym(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 151 def convert_typographic_sym(element) Text.new(Parser::Ext::Entity::TABLE[element.value.to_s]) end
convert_ul(element)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 139 def convert_ul(element) ItemList.new(convert_container(element)) end
in_table_header() { || ... }
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 169 def in_table_header in_table_header, @in_table_header = @in_table_header, true yield ensure @in_table_header = in_table_header end
text(content)
click to toggle source
# File lib/rabbit/parser/markdown/converter.rb, line 89 def text(content) Text.new(Parser::Ext::Escape.escape_meta_character(content)) end