remi-maruku 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. data/Rakefile +73 -0
  2. data/bin/marudown +29 -0
  3. data/bin/maruku +176 -0
  4. data/bin/marutest +338 -0
  5. data/bin/marutex +31 -0
  6. data/docs/changelog.md +334 -0
  7. data/docs/div_syntax.md +36 -0
  8. data/docs/entity_test.md +23 -0
  9. data/docs/markdown_syntax.md +899 -0
  10. data/docs/maruku.md +346 -0
  11. data/docs/math.md +194 -0
  12. data/docs/other_stuff.md +51 -0
  13. data/docs/proposal.md +309 -0
  14. data/lib/maruku.rb +141 -0
  15. data/lib/maruku/attributes.rb +227 -0
  16. data/lib/maruku/defaults.rb +70 -0
  17. data/lib/maruku/errors_management.rb +92 -0
  18. data/lib/maruku/ext/div.rb +100 -0
  19. data/lib/maruku/ext/math.rb +41 -0
  20. data/lib/maruku/ext/math/elements.rb +27 -0
  21. data/lib/maruku/ext/math/latex_fix.rb +11 -0
  22. data/lib/maruku/ext/math/mathml_engines/blahtex.rb +104 -0
  23. data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +29 -0
  24. data/lib/maruku/ext/math/mathml_engines/none.rb +20 -0
  25. data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
  26. data/lib/maruku/ext/math/parsing.rb +105 -0
  27. data/lib/maruku/ext/math/to_html.rb +170 -0
  28. data/lib/maruku/ext/math/to_latex.rb +22 -0
  29. data/lib/maruku/helpers.rb +260 -0
  30. data/lib/maruku/input/charsource.rb +326 -0
  31. data/lib/maruku/input/extensions.rb +69 -0
  32. data/lib/maruku/input/html_helper.rb +189 -0
  33. data/lib/maruku/input/linesource.rb +111 -0
  34. data/lib/maruku/input/parse_block.rb +613 -0
  35. data/lib/maruku/input/parse_doc.rb +227 -0
  36. data/lib/maruku/input/parse_span_better.rb +732 -0
  37. data/lib/maruku/input/rubypants.rb +225 -0
  38. data/lib/maruku/input/type_detection.rb +144 -0
  39. data/lib/maruku/input_textile2/t2_parser.rb +163 -0
  40. data/lib/maruku/maruku.rb +33 -0
  41. data/lib/maruku/output/s5/fancy.rb +756 -0
  42. data/lib/maruku/output/s5/to_s5.rb +125 -0
  43. data/lib/maruku/output/to_html.rb +971 -0
  44. data/lib/maruku/output/to_latex.rb +563 -0
  45. data/lib/maruku/output/to_latex_entities.rb +367 -0
  46. data/lib/maruku/output/to_latex_strings.rb +64 -0
  47. data/lib/maruku/output/to_markdown.rb +164 -0
  48. data/lib/maruku/output/to_s.rb +53 -0
  49. data/lib/maruku/string_utils.rb +191 -0
  50. data/lib/maruku/structures.rb +165 -0
  51. data/lib/maruku/structures_inspect.rb +87 -0
  52. data/lib/maruku/structures_iterators.rb +61 -0
  53. data/lib/maruku/tests/benchmark.rb +82 -0
  54. data/lib/maruku/tests/new_parser.rb +370 -0
  55. data/lib/maruku/tests/tests.rb +136 -0
  56. data/lib/maruku/textile2.rb +1 -0
  57. data/lib/maruku/toc.rb +199 -0
  58. data/lib/maruku/usage/example1.rb +33 -0
  59. data/lib/maruku/version.rb +40 -0
  60. data/tests/bugs/code_in_links.md +16 -0
  61. data/tests/bugs/complex_escaping.md +4 -0
  62. data/tests/math/syntax.md +46 -0
  63. data/tests/math_usage/document.md +13 -0
  64. data/tests/others/abbreviations.md +11 -0
  65. data/tests/others/blank.md +4 -0
  66. data/tests/others/code.md +5 -0
  67. data/tests/others/code2.md +8 -0
  68. data/tests/others/code3.md +16 -0
  69. data/tests/others/email.md +4 -0
  70. data/tests/others/entities.md +19 -0
  71. data/tests/others/escaping.md +16 -0
  72. data/tests/others/extra_dl.md +101 -0
  73. data/tests/others/extra_header_id.md +13 -0
  74. data/tests/others/extra_table1.md +40 -0
  75. data/tests/others/footnotes.md +17 -0
  76. data/tests/others/headers.md +10 -0
  77. data/tests/others/hrule.md +10 -0
  78. data/tests/others/images.md +20 -0
  79. data/tests/others/inline_html.md +42 -0
  80. data/tests/others/links.md +38 -0
  81. data/tests/others/list1.md +4 -0
  82. data/tests/others/list2.md +5 -0
  83. data/tests/others/list3.md +8 -0
  84. data/tests/others/lists.md +32 -0
  85. data/tests/others/lists_after_paragraph.md +44 -0
  86. data/tests/others/lists_ol.md +39 -0
  87. data/tests/others/misc_sw.md +105 -0
  88. data/tests/others/one.md +1 -0
  89. data/tests/others/paragraphs.md +13 -0
  90. data/tests/others/sss06.md +352 -0
  91. data/tests/others/test.md +4 -0
  92. data/tests/s5/s5profiling.md +48 -0
  93. data/tests/unittest/abbreviations.md +72 -0
  94. data/tests/unittest/alt.md +30 -0
  95. data/tests/unittest/attributes/att2.md +34 -0
  96. data/tests/unittest/attributes/att3.md +45 -0
  97. data/tests/unittest/attributes/attributes.md +82 -0
  98. data/tests/unittest/attributes/circular.md +43 -0
  99. data/tests/unittest/attributes/default.md +38 -0
  100. data/tests/unittest/blank.md +39 -0
  101. data/tests/unittest/blanks_in_code.md +106 -0
  102. data/tests/unittest/bug_def.md +29 -0
  103. data/tests/unittest/bug_table.md +67 -0
  104. data/tests/unittest/code.md +53 -0
  105. data/tests/unittest/code2.md +46 -0
  106. data/tests/unittest/code3.md +102 -0
  107. data/tests/unittest/data_loss.md +42 -0
  108. data/tests/unittest/divs/div1.md +204 -0
  109. data/tests/unittest/divs/div2.md +34 -0
  110. data/tests/unittest/divs/div3_nest.md +62 -0
  111. data/tests/unittest/easy.md +28 -0
  112. data/tests/unittest/email.md +33 -0
  113. data/tests/unittest/encoding/iso-8859-1.md +38 -0
  114. data/tests/unittest/encoding/utf-8.md +33 -0
  115. data/tests/unittest/entities.md +124 -0
  116. data/tests/unittest/escaping.md +89 -0
  117. data/tests/unittest/extra_dl.md +72 -0
  118. data/tests/unittest/extra_header_id.md +86 -0
  119. data/tests/unittest/extra_table1.md +55 -0
  120. data/tests/unittest/footnotes.md +126 -0
  121. data/tests/unittest/headers.md +54 -0
  122. data/tests/unittest/hex_entities.md +50 -0
  123. data/tests/unittest/hrule.md +60 -0
  124. data/tests/unittest/html2.md +38 -0
  125. data/tests/unittest/html3.md +47 -0
  126. data/tests/unittest/html4.md +42 -0
  127. data/tests/unittest/html5.md +38 -0
  128. data/tests/unittest/ie.md +82 -0
  129. data/tests/unittest/images.md +114 -0
  130. data/tests/unittest/images2.md +46 -0
  131. data/tests/unittest/inline_html.md +260 -0
  132. data/tests/unittest/inline_html2.md +36 -0
  133. data/tests/unittest/links.md +197 -0
  134. data/tests/unittest/list1.md +66 -0
  135. data/tests/unittest/list2.md +76 -0
  136. data/tests/unittest/list3.md +88 -0
  137. data/tests/unittest/list4.md +116 -0
  138. data/tests/unittest/lists.md +241 -0
  139. data/tests/unittest/lists11.md +31 -0
  140. data/tests/unittest/lists6.md +54 -0
  141. data/tests/unittest/lists7.md +79 -0
  142. data/tests/unittest/lists7b.md +136 -0
  143. data/tests/unittest/lists8.md +83 -0
  144. data/tests/unittest/lists9.md +85 -0
  145. data/tests/unittest/lists_after_paragraph.md +268 -0
  146. data/tests/unittest/lists_ol.md +324 -0
  147. data/tests/unittest/loss.md +29 -0
  148. data/tests/unittest/math/equations.md +69 -0
  149. data/tests/unittest/math/inline.md +66 -0
  150. data/tests/unittest/math/math2.md +110 -0
  151. data/tests/unittest/math/notmath.md +40 -0
  152. data/tests/unittest/math/table.md +43 -0
  153. data/tests/unittest/math/table2.md +60 -0
  154. data/tests/unittest/misc_sw.md +615 -0
  155. data/tests/unittest/notyet/escape.md +36 -0
  156. data/tests/unittest/notyet/header_after_par.md +81 -0
  157. data/tests/unittest/notyet/ticks.md +31 -0
  158. data/tests/unittest/notyet/triggering.md +206 -0
  159. data/tests/unittest/olist.md +64 -0
  160. data/tests/unittest/one.md +28 -0
  161. data/tests/unittest/paragraph.md +29 -0
  162. data/tests/unittest/paragraph_rules/dont_merge_ref.md +57 -0
  163. data/tests/unittest/paragraph_rules/tab_is_blank.md +39 -0
  164. data/tests/unittest/paragraphs.md +66 -0
  165. data/tests/unittest/pending/amps.md +29 -0
  166. data/tests/unittest/pending/empty_cells.md +53 -0
  167. data/tests/unittest/pending/link.md +103 -0
  168. data/tests/unittest/recover/recover_links.md +28 -0
  169. data/tests/unittest/references/long_example.md +88 -0
  170. data/tests/unittest/references/spaces_and_numbers.md +28 -0
  171. data/tests/unittest/smartypants.md +171 -0
  172. data/tests/unittest/syntax_hl.md +80 -0
  173. data/tests/unittest/table_attributes.md +52 -0
  174. data/tests/unittest/test.md +32 -0
  175. data/tests/unittest/wrapping.md +88 -0
  176. data/tests/unittest/xml.md +54 -0
  177. data/tests/unittest/xml2.md +34 -0
  178. data/tests/unittest/xml3.md +44 -0
  179. data/tests/unittest/xml_instruction.md +72 -0
  180. data/tests/utf8-files/simple.md +1 -0
  181. data/unit_test_block.sh +5 -0
  182. data/unit_test_span.sh +2 -0
  183. metadata +243 -0
@@ -0,0 +1,53 @@
1
+ #--
2
+ # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
+ #
4
+ # This file is part of Maruku.
5
+ #
6
+ # Maruku is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Maruku is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Maruku; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+
22
+ module MaRuKu
23
+
24
+ class MDElement
25
+
26
+ # Strips all formatting from the string
27
+ def to_s
28
+ children_to_s
29
+ end
30
+
31
+ def children_to_s
32
+ @children.join
33
+ end
34
+
35
+ # Generate an id for headers. Assumes @children is set.
36
+ def generate_id
37
+ title = children_to_s
38
+ title.gsub!(/ /,'_')
39
+ title.downcase!
40
+ title.gsub!(/[^\w_]/,'')
41
+ title.strip!
42
+
43
+ if title.size == 0
44
+ $uid ||= 0
45
+ $uid += 1
46
+ title = "id#{$uid}"
47
+ end
48
+
49
+ title
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,191 @@
1
+ #--
2
+ # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
+ #
4
+ # This file is part of Maruku.
5
+ #
6
+ # Maruku is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Maruku is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Maruku; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+
22
+ # Boring stuff with strings.
23
+ module MaRuKu; module Strings
24
+
25
+ def add_tabs(s,n=1,char="\t")
26
+ s.split("\n").map{|x| char*n+x }.join("\n")
27
+ end
28
+
29
+ TabSize = 4;
30
+
31
+ def split_lines(s)
32
+ s.gsub("\r","").split("\n")
33
+ end
34
+
35
+ # This parses email headers. Returns an hash.
36
+ #
37
+ # +hash['data']+ is the message.
38
+ #
39
+ # Keys are downcased, space becomes underscore, converted to symbols.
40
+ #
41
+ # My key: true
42
+ #
43
+ # becomes:
44
+ #
45
+ # {:my_key => true}
46
+ #
47
+ def parse_email_headers(s)
48
+ keys={}
49
+ match = (s =~ /((\w[\w\s]+: .*\n)+)\n/)
50
+ if match != 0
51
+ keys[:data] = s
52
+ else
53
+ keys[:data] = $'
54
+ headers = $1
55
+ headers.split("\n").each do |l|
56
+ # Fails if there are other ':' characters.
57
+ # k, v = l.split(':')
58
+ k, v = l.split(':', 2)
59
+ k, v = normalize_key_and_value(k, v)
60
+ k = k.to_sym
61
+ # puts "K = #{k}, V=#{v}"
62
+ keys[k] = v
63
+ end
64
+ end
65
+ keys
66
+ end
67
+
68
+ # Keys are downcased, space becomes underscore, converted to symbols.
69
+ def normalize_key_and_value(k,v)
70
+ v = v ? v.strip : true # no value defaults to true
71
+ k = k.strip
72
+
73
+ # check synonyms
74
+ v = true if ['yes','true'].include?(v.to_s.downcase)
75
+ v = false if ['no','false'].include?(v.to_s.downcase)
76
+
77
+ k = k.downcase.gsub(' ','_')
78
+ return k, v
79
+ end
80
+
81
+ # Returns the number of leading spaces, considering that
82
+ # a tab counts as `TabSize` spaces.
83
+ def number_of_leading_spaces(s)
84
+ n=0; i=0;
85
+ while i < s.size
86
+ c = s[i,1]
87
+ if c == ' '
88
+ i+=1; n+=1;
89
+ elsif c == "\t"
90
+ i+=1; n+=TabSize;
91
+ else
92
+ break
93
+ end
94
+ end
95
+ n
96
+ end
97
+
98
+ # This returns the position of the first real char in a list item
99
+ #
100
+ # For example:
101
+ # '*Hello' # => 1
102
+ # '* Hello' # => 2
103
+ # ' * Hello' # => 3
104
+ # ' * Hello' # => 5
105
+ # '1.Hello' # => 2
106
+ # ' 1. Hello' # => 5
107
+
108
+ def spaces_before_first_char(s)
109
+ case s.md_type
110
+ when :ulist
111
+ i=0;
112
+ # skip whitespace if present
113
+ while s[i,1] =~ /\s/; i+=1 end
114
+ # skip indicator (+, -, *)
115
+ i+=1
116
+ # skip optional whitespace
117
+ while s[i,1] =~ /\s/; i+=1 end
118
+ return i
119
+ when :olist
120
+ i=0;
121
+ # skip whitespace
122
+ while s[i,1] =~ /\s/; i+=1 end
123
+ # skip digits
124
+ while s[i,1] =~ /\d/; i+=1 end
125
+ # skip dot
126
+ i+=1
127
+ # skip whitespace
128
+ while s[i,1] =~ /\s/; i+=1 end
129
+ return i
130
+ else
131
+ tell_user "BUG (my bad): '#{s}' is not a list"
132
+ 0
133
+ end
134
+ end
135
+
136
+ # Counts the number of leading '#' in the string
137
+ def num_leading_hashes(s)
138
+ i=0;
139
+ while i<(s.size-1) && (s[i,1]=='#'); i+=1 end
140
+ i
141
+ end
142
+
143
+ # Strips initial and final hashes
144
+ def strip_hashes(s)
145
+ s = s[num_leading_hashes(s), s.size]
146
+ i = s.size-1
147
+ while i > 0 && (s[i,1] =~ /(#|\s)/); i-=1; end
148
+ s[0, i+1].strip
149
+ end
150
+
151
+ # change space to "_" and remove any non-word character
152
+ def sanitize_ref_id(x)
153
+ x.downcase.gsub(' ','_').gsub(/[^\w]/,'')
154
+ end
155
+
156
+
157
+ # removes initial quote
158
+ def unquote(s)
159
+ s.gsub(/^>\s?/,'')
160
+ end
161
+
162
+ # toglie al massimo n caratteri
163
+ def strip_indent(s, n)
164
+ i = 0
165
+ while i < s.size && n>0
166
+ c = s[i,1]
167
+ if c == ' '
168
+ n-=1;
169
+ elsif c == "\t"
170
+ n-=TabSize;
171
+ else
172
+ break
173
+ end
174
+ i+=1
175
+ end
176
+ s[i, s.size]
177
+ end
178
+
179
+ def dbg_describe_ary(a, prefix='')
180
+ i = 0
181
+ a.each do |l|
182
+ puts "#{prefix} (#{i+=1})# #{l.inspect}"
183
+ end
184
+ end
185
+
186
+ def force_linebreak?(l)
187
+ l =~ / $/
188
+ end
189
+
190
+ end
191
+ end
@@ -0,0 +1,165 @@
1
+ #--
2
+ # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
+ #
4
+ # This file is part of Maruku.
5
+ #
6
+ # Maruku is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Maruku is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Maruku; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+
22
+
23
+ class Module
24
+ def safe_attr_accessor1(symbol, klass)
25
+ attr_reader symbol
26
+ code = <<-EOF
27
+ def #{symbol}=(val)
28
+ if not val.kind_of? #{klass}
29
+ s = "\nCould not assign an object of type \#{val.class} to #{symbol}.\n\n"
30
+ s += "Tried to assign object of class \#{val.class}:\n"+
31
+ "\#{val.inspect}\n"+
32
+ "to \#{self.class}::#{symbol} constrained to be of class #{klass}.\n"
33
+ raise s
34
+ end
35
+ @#{symbol} = val
36
+ end
37
+
38
+ EOF
39
+ module_eval code
40
+ end
41
+
42
+ def safe_attr_accessor2(symbol, klass)
43
+ attr_accessor symbol
44
+ end
45
+
46
+ alias safe_attr_accessor safe_attr_accessor2
47
+ end
48
+
49
+ module MaRuKu
50
+
51
+ # I did not want to have a class for each possible element.
52
+ # Instead I opted to have only the class "MDElement"
53
+ # that represents eveything in the document (paragraphs, headers, etc).
54
+ #
55
+ # You can tell what it is by the variable `node_type`.
56
+ #
57
+ # In the instance-variable `children` there are the children. These
58
+ # can be of class 1) String or 2) MDElement.
59
+ #
60
+ # The @doc variable points to the document to which the MDElement
61
+ # belongs (which is an instance of Maruku, subclass of MDElement).
62
+ #
63
+ # Attributes are contained in the hash `attributes`.
64
+ # Keys are symbols (downcased, with spaces substituted by underscores)
65
+ #
66
+ # For example, if you write in the source document.
67
+ #
68
+ # Title: test document
69
+ # My property: value
70
+ #
71
+ # content content
72
+ #
73
+ # You can access `value` by writing:
74
+ #
75
+ # @doc.attributes[:my_property] # => 'value'
76
+ #
77
+ # from whichever MDElement in the hierarchy.
78
+ #
79
+ class MDElement
80
+ # See helpers.rb for the list of allowed #node_type values
81
+ safe_attr_accessor :node_type, Symbol
82
+
83
+ # Children are either Strings or MDElement
84
+ safe_attr_accessor :children, Array
85
+
86
+ # An attribute list, may not be nil
87
+ safe_attr_accessor :al, Array #Maruku::AttributeList
88
+
89
+ # These are the processed attributes
90
+ safe_attr_accessor :attributes, Hash
91
+
92
+ # Reference of the document (which is of class Maruku)
93
+ attr_accessor :doc
94
+
95
+ def initialize(node_type=:unset, children=[], meta={},
96
+ al=MaRuKu::AttributeList.new )
97
+ super();
98
+ self.children = children
99
+ self.node_type = node_type
100
+
101
+ @attributes = {}
102
+
103
+ meta.each do |symbol, value|
104
+ self.instance_eval "
105
+ def #{symbol}; @#{symbol}; end
106
+ def #{symbol}=(val); @#{symbol}=val; end"
107
+ self.send "#{symbol}=", value
108
+ end
109
+
110
+ self.al = al || AttributeList.new
111
+
112
+ self.meta_priv = meta
113
+ end
114
+
115
+ attr_accessor :meta_priv
116
+
117
+ def ==(o)
118
+ ok = o.kind_of?(MDElement) &&
119
+ (self.node_type == o.node_type) &&
120
+ (self.meta_priv == o.meta_priv) &&
121
+ (self.children == o.children)
122
+
123
+ if not ok
124
+ # puts "This:\n"+self.inspect+"\nis different from\n"+o.inspect+"\n\n"
125
+ end
126
+ ok
127
+ end
128
+ end
129
+
130
+ # This represents the whole document and holds global data.
131
+
132
+ class MDDocument
133
+
134
+ safe_attr_accessor :refs, Hash
135
+ safe_attr_accessor :footnotes, Hash
136
+
137
+ # This is an hash. The key might be nil.
138
+ safe_attr_accessor :abbreviations, Hash
139
+
140
+ # Attribute lists definition
141
+ safe_attr_accessor :ald, Hash
142
+
143
+ # The order in which footnotes are used. Contains the id.
144
+ safe_attr_accessor :footnotes_order, Array
145
+
146
+ safe_attr_accessor :latex_required_packages, Array
147
+
148
+ def initialize(s=nil)
149
+ super(:document)
150
+ @doc = self
151
+
152
+ self.refs = {}
153
+ self.footnotes = {}
154
+ self.footnotes_order = []
155
+ self.abbreviations = {}
156
+ self.ald = {}
157
+ self.latex_required_packages = []
158
+
159
+ parse_doc(s) if s
160
+ end
161
+ end
162
+
163
+
164
+ end # MaRuKu
165
+
@@ -0,0 +1,87 @@
1
+ #--
2
+ # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
+ #
4
+ # This file is part of Maruku.
5
+ #
6
+ # Maruku is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Maruku is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Maruku; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
21
+
22
+
23
+ class String
24
+ def inspect_more(a=nil,b=nil)
25
+ inspect
26
+ end
27
+ end
28
+
29
+ class Object
30
+ def inspect_more(a=nil,b=nil)
31
+ inspect
32
+ end
33
+ end
34
+
35
+ class Array
36
+ def inspect_more(compact, join_string, add_brackets=true)
37
+ s = map {|x|
38
+ x.kind_of?(String) ? x.inspect :
39
+ x.kind_of?(MaRuKu::MDElement) ? x.inspect(compact) :
40
+ (raise "WTF #{x.class} #{x.inspect}")
41
+ }.join(join_string)
42
+
43
+ add_brackets ? "[#{s}]" : s
44
+ end
45
+ end
46
+
47
+ class Hash
48
+ def inspect_ordered(a=nil,b=nil)
49
+ "{"+keys.map{|x|x.to_s}.sort.map{|x|x.to_sym}.
50
+ map{|k| k.inspect + "=>"+self[k].inspect}.join(',')+"}"
51
+ end
52
+ end
53
+
54
+ module MaRuKu
55
+ class MDElement
56
+ def inspect(compact=true)
57
+ if compact
58
+ i2 = inspect2
59
+ return i2 if i2
60
+ end
61
+
62
+ "md_el(:%s,%s,%s,%s)" %
63
+ [
64
+ self.node_type,
65
+ children_inspect(compact),
66
+ @meta_priv.inspect_ordered,
67
+ self.al.inspect
68
+ ]
69
+ end
70
+
71
+ def children_inspect(compact=true)
72
+ s = @children.inspect_more(compact,', ')
73
+ if @children.empty?
74
+ "[]"
75
+ elsif s.size < 70
76
+ s
77
+ else
78
+ "[\n"+
79
+ add_tabs(@children.inspect_more(compact,",\n",false))+
80
+ "\n]"
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+