Class: MaRuKu::MDElement
- Inherits:
-
Object
- Object
- MaRuKu::MDElement
- Includes:
- MaRuKu, Defaults, Errors, Helpers, Out::HTML, Out::Latex, Out::Markdown, Strings
- Defined in:
- lib/maruku/structures.rb,
lib/maruku.rb,
lib/maruku/helpers.rb,
lib/maruku/output/to_s.rb,
lib/maruku/structures_inspect.rb,
lib/maruku/structures_iterators.rb
Overview
from whichever MDElement in the hierarchy.
Direct Known Subclasses
Constant Summary
Constants included from Errors
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 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
Instance Attribute Summary collapse
-
#doc ⇒ Object
Reference of the document (which is of class Maruku).
-
#meta_priv ⇒ Object
Returns the value of attribute meta_priv.
Class Method Summary collapse
-
.init_tables ⇒ Object
create hash @@entity_to_latex.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #children_inspect(compact = true) ⇒ Object
- #children_to_s ⇒ Object
-
#each_element(e_node_type = nil, &block) ⇒ Object
Yields to each element of specified node_type All elements if e_node_type is nil.
-
#generate_id ⇒ Object
Generate an id for headers.
-
#initialize(node_type = :unset, children = [], meta = {}, al = MaRuKu::AttributeList.new) ⇒ MDElement
constructor
A new instance of MDElement.
- #inspect(compact = true) ⇒ Object
-
#inspect2 ⇒ Object
outputs abbreviated form (this should be eval()uable to get the document).
-
#replace_each_string(&block) ⇒ Object
Apply passed block to each String in the hierarchy.
-
#to_s ⇒ Object
Strips all formatting from the string.
Methods included from Errors
#create_frame, #describe_error, #maruku_error, #maruku_recover, #raise_error, #tell_user
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 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, #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(node_type = :unset, children = [], meta = {}, al = MaRuKu::AttributeList.new) ⇒ MDElement
Returns a new instance of MDElement.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/maruku/structures.rb', line 94 def initialize(node_type=:unset, children=[], ={}, al=MaRuKu::AttributeList.new ) super(); self.children = children self.node_type = node_type @attributes = {} .each do |symbol, value| self.instance_eval " def #{symbol}; @#{symbol}; end def #{symbol}=(val); @#{symbol}=val; end" self.send "#{symbol}=", value end self.al = al || AttributeList.new self. = end |
Instance Attribute Details
#doc ⇒ Object
Reference of the document (which is of class Maruku)
92 93 94 |
# File 'lib/maruku/structures.rb', line 92 def doc @doc end |
#meta_priv ⇒ Object
Returns the value of attribute meta_priv.
114 115 116 |
# File 'lib/maruku/structures.rb', line 114 def @meta_priv end |
Class Method Details
.init_tables ⇒ Object
create hash @@entity_to_latex
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/maruku/output/to_latex_entities.rb', line 45 def MDElement.init_tables ## why can't I use a class variable? if not $conversion_table_inited doc = Document.new XML_TABLE @@entity_to_latex = {} doc.elements.each("//char") do |c| num = c.attributes['num'] name = c.attributes['name'] convert = c.attributes['convertTo'] @@entity_to_latex["#{num}"] = convert @@entity_to_latex["#{name}"] = convert end # puts @@entity_to_latex.inspect $conversion_table_inited = true end end |
Instance Method Details
#==(o) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/maruku/structures.rb', line 116 def ==(o) ok = o.kind_of?(MDElement) && (self.node_type == o.node_type) && (self. == o.) && (self.children == o.children) if not ok # puts "This:\n"+self.inspect+"\nis different from\n"+o.inspect+"\n\n" end ok end |
#children_inspect(compact = true) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/maruku/structures_inspect.rb', line 62 def children_inspect(compact=true) s = @children.inspect_more(compact,', ') if @children.empty? "[]" elsif s.size < 70 s else "[\n"+ add_tabs(@children.inspect_more(compact,",\n",false))+ "\n]" end end |
#children_to_s ⇒ Object
31 32 33 |
# File 'lib/maruku/output/to_s.rb', line 31 def children_to_s @children.join end |
#each_element(e_node_type = nil, &block) ⇒ Object
Yields to each element of specified node_type All elements if e_node_type is nil.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/maruku/structures_iterators.rb', line 28 def each_element(e_node_type=nil, &block) @children.each do |c| if c.kind_of? MDElement if (not e_node_type) || (e_node_type == c.node_type) block.call c end c.each_element(e_node_type, &block) end end end |
#generate_id ⇒ Object
Generate an id for headers. Assumes @children is set.
36 37 38 39 40 41 42 |
# File 'lib/maruku/output/to_s.rb', line 36 def generate_id title = children_to_s title.gsub!(/ /,'_') title.downcase! title.gsub!(/[^\w_]/,'') title end |
#inspect(compact = true) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/maruku/structures_inspect.rb', line 47 def inspect(compact=true) if compact i2 = inspect2 return i2 if i2 end "md_el(:%s,%s,%s,%s)" % [ self.node_type, children_inspect(compact), @meta_priv.inspect_ordered, self.al.inspect ] end |
#inspect2 ⇒ Object
outputs abbreviated form (this should be eval()uable to get the document)
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/maruku/helpers.rb', line 183 def inspect2 s = case @node_type when :paragraph "md_par(%s)" % children_inspect when :footnote_reference "md_foot_ref(%s)" % self.footnote_id.inspect when :entity "md_entity(%s)" % self.entity_name.inspect when :email_address "md_email(%s)" % self.email.inspect when :inline_code "md_code(%s)" % self.raw_code.inspect when :raw_html "md_html(%s)" % self.raw_html.inspect when :emphasis "md_em(%s)" % children_inspect when :strong "md_strong(%s)" % children_inspect when :immediate_link "md_url(%s)" % self.url.inspect when :image "md_image(%s, %s)" % [ children_inspect, self.ref_id.inspect] when :im_image "md_im_image(%s, %s, %s)" % [ children_inspect, self.url.inspect, self.title.inspect] when :link "md_link(%s,%s)" % [ children_inspect, self.ref_id.inspect] when :im_link "md_im_link(%s, %s, %s)" % [ children_inspect, self.url.inspect, self.title.inspect, ] when :ref_definition "md_ref_def(%s, %s, %s)" % [ self.ref_id.inspect, self.url.inspect, self.title.inspect ] when :ial "md_ial(%s)" % self.ial.inspect else return nil end if @al and not @al.empty? then s = s.chop + ", #{@al.inspect})" end s end |
#replace_each_string(&block) ⇒ Object
Apply passed block to each String in the hierarchy.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/maruku/structures_iterators.rb', line 40 def replace_each_string(&block) for c in @children if c.kind_of? MDElement c.replace_each_string(&block) end end processed = [] until @children.empty? c = @children.shift if c.kind_of? String result = block.call(c) [*result].each do |e| processed << e end else processed << c end end @children = processed end |
#to_s ⇒ Object
Strips all formatting from the string
27 28 29 |
# File 'lib/maruku/output/to_s.rb', line 27 def to_s children_to_s end |