Class: MaRuKu::MDDocument

Inherits:
MDElement show all
Includes:
In::Markdown::BlockLevelParser, In::Markdown::SpanLevelParser
Defined in:
lib/maruku/structures.rb,
lib/maruku.rb,
lib/maruku/toc.rb,
lib/maruku/toc.rb,
lib/maruku/output/to_latex.rb,
lib/maruku/output/to_markdown.rb

Overview

This represents the whole document and holds global data.

Direct Known Subclasses

Maruku

Constant Summary

Constants included from In::Markdown::SpanLevelParser

In::Markdown::SpanLevelParser::CharSource, In::Markdown::SpanLevelParser::EscapedCharInInlineCode, In::Markdown::SpanLevelParser::EscapedCharInQuotes, In::Markdown::SpanLevelParser::EscapedCharInText, In::Markdown::SpanLevelParser::R_REF_ID, In::Markdown::SpanLevelParser::SPACE

Constants included from Strings

Strings::Abbreviation, Strings::AttributeDefinitionList, Strings::Definition, Strings::EMailAddress, Strings::FootnoteText, Strings::HeaderWithAttributes, Strings::HeaderWithId, Strings::IncompleteLink, Strings::LinkRegex, Strings::MightBeTableHeader, Strings::Sep, Strings::TabSize, Strings::TableSeparator, Strings::URL

Constants included from Errors

Errors::Default_on_error

Constants included from Out::Latex

Out::Latex::TexHeaders, Out::Latex::XML_TABLE

Constants included from Defaults

Defaults::DEFAULT_CODE_COLOR, Defaults::DefaultAttributes

Constants included from Out::Markdown

Out::Markdown::DefaultLineLength

Constants included from MaRuKu

MarukuURL, Version

Instance Attribute Summary collapse

Attributes inherited from MDElement

#doc, #meta_priv

Instance Method Summary collapse

Methods included from In::Markdown::BlockLevelParser

#eventually_comes_a_def_list, #expand_attribute_list, #parse_blocks, #parse_doc, #parse_text_as_markdown, #read_abbreviation, #read_ald, #read_code, #read_definition, #read_footnote_text, #read_header12, #read_header3, #read_indented_content, #read_list_item, #read_metadata, #read_paragraph, #read_quote, #read_raw_html, #read_ref_definition, #read_table, #search_abbreviations, #split_cells, #substitute_markdown_inside_raw_html

Methods included from In::Markdown::SpanLevelParser

#describe_pos, #is_ial, #md_al, #parse_lines_as_span, #parse_span_better, #read_attribute_list, #read_em, #read_email_el, #read_emstrong, #read_footnote_ref, #read_image, #read_inline_code, #read_inline_html, #read_link, #read_quoted, #read_quoted_or_unquoted, #read_ref_id, #read_server_directive, #read_simple, #read_span, #read_strong, #read_url, #read_url_el, #unit_tests_for_attribute_lists

Methods included from Helpers

#md_abbr, #md_abbr_def, #md_ald, #md_br, #md_code, #md_codeblock, #md_el, #md_em, #md_email, #md_emstrong, #md_entity, #md_foot_ref, #md_footnote, #md_header, #md_hrule, #md_html, #md_ial, #md_im_image, #md_im_link, #md_image, #md_li, #md_link, #md_par, #md_quote, #md_ref_def, #md_server, #md_strong, #md_url

Methods included from Strings

#add_tabs, #dbg_describe_ary, #force_linebreak?, #line_md_type, #normalize_key_and_value, #num_leading_hashes, #number_of_leading_spaces, #parse_email_headers, #spaces_before_first_char, #split_lines, #strip_hashes, #strip_indent, #unquote

Methods inherited from MDElement

#==, #children_inspect, #children_to_s, #each_element, #generate_id, init_tables, #inspect, #inspect2, #replace_each_string, #to_s

Methods included from Errors

#create_frame, #describe_error, #maruku_error, #maruku_recover, #raise_error, #tell_user

Methods included from Out::Latex

#array_to_latex, #children_to_latex, #get_setting, #latex_color, #latex_escape, #to_latex_abbr, #to_latex_cell, #to_latex_code, #to_latex_definition, #to_latex_definition_list, #to_latex_email_address, #to_latex_emphasis, #to_latex_entity, #to_latex_footnote_reference, #to_latex_head_cell, #to_latex_header, #to_latex_hrule, #to_latex_image, #to_latex_immediate_link, #to_latex_inline_code, #to_latex_li, #to_latex_li_span, #to_latex_linebreak, #to_latex_link, #to_latex_ol, #to_latex_paragraph, #to_latex_quote, #to_latex_raw_html, #to_latex_strong, #to_latex_table, #to_latex_ul, #wrap_as_environment, #wrap_as_span

Methods included from Out::HTML

#add_whitespace, #add_ws, #array_to_html, #children_to_html, #create_html_element, #day_suffix, #maruku_html_signature, #nice_date, #obfuscate, #render_footnotes, #render_section_number, #section_number, #source2html, #to_html, #to_html_abbr, #to_html_cell, #to_html_code, #to_html_code_using_pre, #to_html_definition, #to_html_definition_data, #to_html_definition_list, #to_html_definition_term, #to_html_document, #to_html_document_tree, #to_html_email_address, #to_html_emphasis, #to_html_entity, #to_html_footnote_reference, #to_html_head_cell, #to_html_header, #to_html_hrule, #to_html_im_image, #to_html_im_link, #to_html_image, #to_html_immediate_link, #to_html_inline_code, #to_html_li, #to_html_li_span, #to_html_linebreak, #to_html_link, #to_html_ol, #to_html_paragraph, #to_html_quote, #to_html_raw_html, #to_html_ref_definition, #to_html_strong, #to_html_table, #to_html_ul, #to_latex_ref_definition, #wrap_as_element

Methods included from Out::Markdown

#add_indent, #array_to_md, #children_to_md, #to_md_abbr_def, #to_md_li_span, #to_md_ol, #to_md_paragraph, #to_md_ul, #wrap

Methods included from MaRuKu

#markdown_extra?, #new_meta_data?

Constructor Details

#initialize(s = nil) ⇒ MDDocument

Returns a new instance of MDDocument.



144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/maruku/structures.rb', line 144

def initialize(s=nil)
	super(:document)
	@doc       = self

	self.refs = {}
	self.footnotes = {}
	self.footnotes_order = []
	self.abbreviations = {}
	self.ald = {}
	
	parse_doc(s) if s 
end

Instance Attribute Details

#tocObject

an instance of Section (see below)



26
27
28
# File 'lib/maruku/toc.rb', line 26

def toc
  @toc
end

Instance Method Details

#create_tocObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/maruku/toc.rb', line 135

def create_toc
	each_element(:header) do |h|
		h.attributes[:id] ||= h.generate_id
	end

	stack = []

	# the ancestor section
	s = Section.new
	s.section_level = 0

	stack.push s
	
	i = 0;
	while i < @children.size
		while i < @children.size 
			if @children[i].node_type == :header
				level = @children[i].level
				break if level <= stack.last.section_level+1
			end
		
			stack.last.immediate_children.push @children[i]
			i += 1
		end

		break if i>=@children.size
	
		header = @children[i]
		level = header.level
	
		if level > stack.last.section_level
			# this level is inside
		
			s2 = Section.new
			s2.section_level = level
			s2.header_element = header
			header.instance_variable_set :@section, s2
		
			stack.last.section_children.push s2
			stack.push s2
		
			i+=1
		elsif level == stack.last.section_level
			# this level is a sibling
			stack.pop
		else 
			# this level is a parent
			stack.pop
		end
	
	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

#old_mdObject



158
# File 'lib/maruku/output/to_markdown.rb', line 158

alias old_md to_md

#render_latex_signatureObject



60
61
62
63
64
65
66
67
# File 'lib/maruku/output/to_latex.rb', line 60

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

#to_latexObject

Render as a LaTeX fragment



28
29
30
# File 'lib/maruku/output/to_latex.rb', line 28

def to_latex
	children_to_latex
end

#to_latex_documentObject

Render as a complete LaTeX document



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/maruku/output/to_latex.rb', line 33

def to_latex_document
	header = ""
	
	if @doc.attributes[:latex_use_listings]
		header += "\\usepackage{listings}\n"
	end

	body = to_latex
	
	body += render_latex_signature

"\\documentclass{article}
#{header}
\\usepackage{hyperref}
\\usepackage{xspace}
\\usepackage[usenames,dvipsnames]{color}
\\usepackage[margin=1in]{geometry}
\\hypersetup{colorlinks=true}
%\\usepackage{ucs}
%\\usepackage[utf8x]{inputenc}
\\begin{document} 
#{body}
\\end{document}
"	
end

#to_md(context = {}) ⇒ Object



159
160
161
162
163
# File 'lib/maruku/output/to_markdown.rb', line 159

def to_md(context={})
	s = old_md(context)
#		puts s
	s
end