Class: MaRuKu::MDDocument

### Home Classes Methods

### In Files

- lib/maruku/ext/math/parsing.rb
- lib/maruku/input_textile2/t2_parser.rb
- lib/maruku/output/s5/to_s5.rb
- lib/maruku/output/to_latex.rb
- lib/maruku/output/to_markdown.rb
- lib/maruku/structures.rb
- lib/maruku/toc.rb
- lib/maruku.rb

### Parent

MaRuKu::MDElement

### Methods

- ::new
- #create_toc
- #html_escape
- #is_math_enabled?
- #latex_require_package
- #old_md
- #render_latex_signature
- #s5_theme
- #t2_block_paragraph
- #t2_parse
- #t2_parse_blocks
- #t2_parse_span
- #to_latex
- #to_latex_document
- #to_md
- #to_s5

### Included Modules

- MaRuKu::In::Markdown
- MaRuKu::In::Markdown::SpanLevelParser
- MaRuKu::In::Markdown::BlockLevelParser

### Class/Module Index

Quicksearch

- MaRuKu
- MaRuKu::Errors
- MaRuKu::Exception
- MaRuKu::Helpers
- MaRuKu::In
- MaRuKu::In::Markdown
- MaRuKu::In::Markdown::BlockLevelParser
- MaRuKu::In::Markdown::BlockLevelParser::BlockContext
- MaRuKu::In::Markdown::BlockLevelParser::LineSource
- MaRuKu::In::Markdown::SpanExtension
- MaRuKu::In::Markdown::SpanLevelParser
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceDebug
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceManual
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceStrscan
- MaRuKu::In::Markdown::SpanLevelParser::HTMLHelper
- MaRuKu::In::Markdown::SpanLevelParser::SpanContext
- MaRuKu::MDDocument
- MaRuKu::MDElement
- MaRuKu::Out
- MaRuKu::Out::HTML
- MaRuKu::Out::Latex
- MaRuKu::Out::Latex::LatexEntity
- MaRuKu::Out::Markdown
- MaRuKu::Section
- MaRuKu::Strings
- MaRuKu::Tests
- Array
- Hash
- Maruku
- Module
- NilClass
- Object
- String
- Textile2Signature

No matching classes.

# MaRuKu::MDDocument

This represents the whole document and holds global data.

### Constants

Handling
Latex_preamble_enc_cjk
Latex_preamble_enc_utf8
T2_Handling

### Attributes

### Public Class Methods

new(s=nil) click to toggle source

    # File lib/maruku/structures.rb, line 150
    def initialize(s=nil)
            super(:document)
            @doc       = self

            self.refs = {}
            self.footnotes = {}
            self.footnotes_order = []
            self.abbreviations = {}
            self.ald = {}
            self.latex_required_packages = []

            parse_doc(s) if s
    end

### Public Instance Methods

html_escape(string) click to toggle source

    # File lib/maruku/output/s5/to_s5.rb, line 18
    def  html_escape(string)
      string.gsub( /&/, "&amp;" ).
             gsub( /</, "&lt;" ).
             gsub( />/, "&gt;" ).
             gsub( /'/, "&#39;" ).
             gsub( /"/, "&quot;" )
    end

is_math_enabled?() click to toggle source

    # File lib/maruku/ext/math/parsing.rb, line 7
    def is_math_enabled?
            get_setting :math_enabled
    end

latex_require_package(p) click to toggle source

    # File lib/maruku/output/to_latex.rb, line 34
    def latex_require_package(p)
            if not self.latex_required_packages.include? p
                    self.latex_required_packages.push p
            end
    end

old_md(context={}) click to toggle source
Alias for: to_md
render_latex_signature() click to toggle source

    # File lib/maruku/output/to_latex.rb, line 141
            def render_latex_signature
    "\\vfill
    \\hrule
    \\vspace{1.2mm}
    \\begin{tiny}
    Created by \\href{http://maruku.rubyforge.org}{Maruku} #{self.nice_date}.
    \\end{tiny}"
            end

s5_theme() click to toggle source

    # File lib/maruku/output/s5/to_s5.rb, line 14
    def s5_theme
      html_escape(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_latex() click to toggle source

Render as a LaTeX fragment

    # File lib/maruku/output/to_latex.rb, line 41
    def to_latex
            children_to_latex
    end

to_latex_document() click to toggle source

Attribute: maruku_signature Scope: document Output: html, latex Summary: Enables Maruku's signature. Default: true

If false, Maruku does not append a signature to the generated file.

# Render as a complete LaTeX document

    # File lib/maruku/output/to_latex.rb, line 57
            def to_latex_document
                    body = to_latex

                    if get_setting(:maruku_signature)
                            body += render_latex_signature
                    end

                    required =
                    self.latex_required_packages.map {|p|
                            "\\usepackage{#{p}}\n"
                    }.join

    Attribute: latex_cjk
    Scope:     document
    Output:    latex
    Summary:   Support for CJK characters.

    If the `latex_cjk` attribute is specified, then appropriate headers
    are added to the LaTeX preamble to support Japanese fonts.
    You have to have these fonts installed -- and this can be a pain.

    If `latex_cjk` is specified, this is added to the preamble:

    <?mrk puts "ciao" ?>

    <?mrk md_codeblock(Maruku::MDDocument::Latex_preamble_enc_cjk) ?>

    while the default is to add this:

    <?mrk md_codeblock(Maruku::MDDocument::Latex_preamble_enc_utf8) ?>

                    encoding = get_setting(:latex_cjk) ?
                            Latex_preamble_enc_cjk : Latex_preamble_enc_utf8

    Attribute: latex_preamble
    Scope:     document
    Output:    latex
    Summary:   User-defined preamble.

    If the `latex_preamble` attribute is specified, then its value
    will be used as a custom preamble.

    For example:

            Title: My document
            Latex preamble: preamble.tex

    will produce:

            ...
            \input{preamble.tex}
            ...

            user_preamble = (file = @doc.attributes[:latex_preamble]) ?
                    "\\input{#{file}}\n" : ""

    "\\documentclass{article}

    % Packages required to support encoding
    #{encoding}

    % Packages required by code
    #{required}

    % Packages always used
    \\usepackage{hyperref}
    \\usepackage{xspace}
    \\usepackage[usenames,dvipsnames]{color}
    \\hypersetup{colorlinks=true,urlcolor=blue}

    #{user_preamble}

    \\begin{document}
    #{body}
    \\end{document}
    "
            end

to_md(context={}) click to toggle source

    # File lib/maruku/output/to_markdown.rb, line 159
            def to_md(context={})
                    s = old_md(context)
    #               puts s
                    s
            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 27
    def to_s5(context={})
            indent       = context[:indent]       || -1
            ie_hack      = !context[:ie_hack].kind_of?(FalseClass)
            content_only = !context[:content_only].kind_of?(FalseClass)

            doc = Document.new(nil,{:respect_whitespace =>:all})

            if content_only
                    body = Element.new('div', doc)
            else
                    html = Element.new('html', doc)
                    html.add_namespace('http://www.w3.org/1999/xhtml')
                    html.add_namespace('svg', "http://www.w3.org/2000/svg" )

                    head = Element.new('head', html)
                    me = Element.new 'meta', head
                    me.attributes['http-equiv'] = 'Content-type'
                    me.attributes['content'] = 'text/html;charset=utf-8'

                    # Create title element
                    doc_title = self.attributes[:title] || self.attributes[:subject] || ""
                    title = Element.new 'title', head
                            title << Text.new(doc_title)
                    body = Element.new('body', html)

            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.add_element Document.new(dummy_layout_slide, {:respect_whitespace =>:all}).root

            presentation = Element.new 'div', body
            presentation.attributes['class'] = '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.add_element Document.new(first_slide).root

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

                    puts "Slide #{slide_num}: " + slide.header_element.to_s
                    div = Element.new('div', presentation)
                    div.attributes['class'] = 'slide'

                    h1 = Element.new 'h1', div
                    slide.header_element.children_to_html.each do |e| h1 << e; end

                    array_to_html(slide.immediate_children).each do |e|  div << e  end

                    # render footnotes
                    if @doc.footnotes_order.size > 0
                            div << render_footnotes
                            @doc.footnotes_order = []
                    end
            end

            xml  = ""
            if (content_only)
               if $rexml_new_version
                 formatter = REXML::Formatters::Default.new(ie_hack)
                 formatter.write(body, xml)
               else
                 body.write(xml,indent,transitive=true,ie_hack);
              end
            else
              doc2 = Document.new("<div>"+S5_external+"</div>",{:respect_whitespace =>:all})
              doc2.root.children.each{ |child| head << child }

              add_css_to(head)

              # REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
              # containing code.
              html.write(xml,indent,transitive=true,ie_hack);
              Xhtml11_mathml2_svg11 + xml
            end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.