class MaRuKu::MDDocument

This represents the whole document and holds global data.

Constants

Handling
T2_Handling

Attributes

abbreviations[RW]

@return [{String => String}]

ald[RW]

Attribute definition lists.

@return [{String => AttributeList}]

eqid2eq[RW]

A hash of equation ids to equation elements

@return [String => MDElement]

footnotes[RW]

@return [{String => MDElement}]

footnotes_order[RW]

The order in which footnotes are used. Contains the id.

@return [Array<String>]

header_ids[RW]

A map of header IDs to a count of how many times they've occurred in the document.

@return [Hash<String, Number>]

id_counter[RW]

A counter for generating unique IDs [Integer]

refid2ref[RW]

@return [{String => {String => MDElement}}]

refs[RW]

@return [{String => {:url => String, :title => String}}]

toc[RW]

The table of contents for the document.

@return [Section]

Public Class Methods

new(s=nil) click to toggle source
# File lib/maruku/document.rb, line 29
def initialize(s=nil)
  super(:document)

  self.doc = self
  self.refs = {}
  self.footnotes = {}
  self.footnotes_order = []
  self.abbreviations = {}
  self.ald = {}
  self.id_counter = 0

  parse_doc(s) if s
end

Public Instance Methods

create_toc() click to toggle source
# File lib/maruku/toc.rb, line 133
def create_toc
  self.header_ids = Hash.new(0)

  each_element(:header) {|h| h.attributes[:id] ||= h.generate_id }


  # The root section
  s = Section.new
  s.section_level = 0

  stack = [s]

  i = 0
  while i < @children.size
    if children[i].node_type == :header
      header = @children[i]
      level = header.level
      s2 = Section.new
      s2.section_level = level
      s2.header_element = header
      header.instance_variable_set :@section, s2
      while level <= stack.last.section_level
        stack.pop
      end
      stack.last.section_children.push s2
      stack.push s2
    else
      stack.last.immediate_children.push @children[i]
    end
    i += 1
  end

  # If there is only one big header, then assume
  # it is the master
  if s.section_children.size == 1
    s = s.section_children.first
  end

  # Assign section numbers
  s.numerate

  s
end
is_math_enabled?() click to toggle source
# File lib/maruku/ext/math/parsing.rb, line 8
def is_math_enabled?
  get_setting :math_enabled
end
old_md(context={})
Alias for: to_md
s5_theme() click to toggle source
# File lib/maruku/output/s5/to_s5.rb, line 5
def s5_theme
  xtext(self.attributes[:slide_theme] || "default")
end
t2_block_paragraph(src, output, signature, lines) click to toggle source
# File lib/maruku/input_textile2/t2_parser.rb, line 151
                def t2_block_paragraph(src, output, signature, lines)
                        paragraph = lines.join("\n")
                        src2 = CharSource.new(paragraph, src)
#                       output = 
                end
t2_parse(source, params) click to toggle source
# File lib/maruku/input_textile2/t2_parser.rb, line 95
def t2_parse(source, params)
        src = LineSource.new(source)
        output = BlockContext.new
        t2_parse_blocks(src, output)
        self.children = output.elements
end
t2_parse_blocks(src, output) click to toggle source

Input is a LineSource

# File lib/maruku/input_textile2/t2_parser.rb, line 109
def t2_parse_blocks(src, output)
        while src.cur_line
                l = src.shift_line
                
                # ignore empty line
                if l.t2_empty? then 
                        src.shift_line
                        next 
                end
                
                # TODO: lists
                # TODO: xml
                # TODO: `==`

                signature, l =
                        if l.t2_contains_signature?
                                l.t2_get_signature
                        else
                                [Textile2Signature.new, l]
                        end

                if handling = T2_Handling.has_key?(signature.block_name)
                        if self.responds_to? handling.method
                                # read as many non-empty lines that you can
                                lines = [l]
                                if handling.parse_lines
                                        while not src.cur_line.t2_empty?
                                                lines.push src.shift_line
                                        end
                                end
                        
                                self.send(handling.method, src, output, signature, lines)
                        else
                                maruku_error("We don't know about method #{handling.method.inspect}")
                                next
                        end
                end
                
                
        end
end
t2_parse_span(src, output) click to toggle source
# File lib/maruku/input_textile2/t2_parser.rb, line 157
def t2_parse_span(src, output)
        
end
to_md(context={}) click to toggle source
# File lib/maruku/output/to_markdown.rb, line 204
def to_md(context={})
  warn "Maruku#to_md is deprecated and will be removed in a near-future version of Maruku."
  old_md(context)
end
Also aliased as: old_md
to_s5(context={}) click to toggle source

Render as an HTML fragment (no head, just the content of BODY). (returns a string)

# File lib/maruku/output/s5/to_s5.rb, line 10
def to_s5(context={})
  content_only = context[:content_only] != false
  print_slides = context[:print_slides]

  if content_only
    body = xelem('div', doc)
  else
    html = xelem('html')
    html['xmlns'] = 'http://www.w3.org/1999/xhtml'
    html['xmlns:svg'] = "http://www.w3.org/2000/svg"
    html['xml:lang'] = self.attributes[:lang] || 'en'

    head = xelem('head')
    html << head

    me = xelem('meta')
    me['http-equiv'] = 'Content-type'
    me['content'] = 'text/html;charset=utf-8'
    head << me

    # Create title element
    doc_title = self.attributes[:title] || self.attributes[:subject] || ""
    begin
      title_content = MaRuKu::HTMLFragment.new(doc_title).to_html
    rescue
      title_content = xtext(doc_title)
    end
    title = xelem('title') << title_content
    head << title

    body = xelem('body')
    html << body
  end

  slide_header = self.attributes[:slide_header]
  slide_footer = self.attributes[:slide_footer]
  slide_subfooter = self.attributes[:slide_subfooter]
  slide_topleft  = self.attributes[:slide_topleft]
  slide_topright  = self.attributes[:slide_topright]
  slide_bottomleft  = self.attributes[:slide_bottomleft]
  slide_bottomright  = self.attributes[:slide_bottomright]

  dummy_layout_slide = "
<div class='layout'>
<div id='controls'> </div>
<div id='currentSlide'> </div>
<div id='header'> #{slide_header}</div>
<div id='footer'>
<h1>#{slide_footer}</h1>
<h2>#{slide_subfooter}</h2>
</div>
<div class='topleft'> #{slide_topleft}</div>
<div class='topright'> #{slide_topright}</div>
<div class='bottomleft'> #{slide_bottomleft}</div>
<div class='bottomright'> #{slide_bottomright}</div>
</div>
            "
  body <<  dummy_layout_slide

  presentation = xelem('div')
  presentation['class'] = 'presentation'
  body << presentation

  first_slide = "
<div class='slide'>
<h1> #{self.attributes[:title] ||context[:title]}</h1>
<h2> #{self.attributes[:subtitle] ||context[:subtitle]}</h2>
<h3> #{self.attributes[:author] ||context[:author]}</h3>
<h4> #{self.attributes[:company] ||context[:company]}</h4>
</div>
"
  presentation << first_slide

  slide_num = 0
  self.toc.section_children.each do |slide|
    slide_num += 1
    @doc.attributes[:doc_prefix] = "s#{slide_num}"

    div = xelem('div')
    presentation << div
    div['class'] = 'slide'

    h1 = xelem('h1')
    puts "Slide #{slide_num}: #{slide.header_element.children_to_html.join}" if print_slides
    slide.header_element.children_to_html.inject(h1, &:<<)
    div << h1

    array_to_html(slide.immediate_children).inject(div, &:<<)

    # render footnotes
    unless @doc.footnotes_order.empty?
      div << render_footnotes
      @doc.footnotes_order = []
    end
  end

  if content_only
    xml = body.to_html
  else
    head << S5_external

    add_css_to(head)

    xml = html.to_html
    Xhtml11_mathml2_svg11 + xml
  end
end