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,73 @@
1
+ require 'rubygems'
2
+ Gem::manage_gems
3
+ require 'rake/gempackagetask'
4
+
5
+ require 'maruku_gem'
6
+
7
+ task :default => [:package]
8
+
9
+ Rake::GemPackageTask.new($spec) do |pkg|
10
+ pkg.need_zip = true
11
+ pkg.need_tar = true
12
+ end
13
+
14
+ PKG_NAME = 'maruku'
15
+ PKG_FILE_NAME = "#{PKG_NAME}-#{MaRuKu::Version}"
16
+ RUBY_FORGE_PROJECT = PKG_NAME
17
+ RUBY_FORGE_USER = 'andrea'
18
+
19
+ RELEASE_NAME = MaRuKu::Version
20
+ RUBY_FORGE_GROUPID = '2795'
21
+ RUBY_FORGE_PACKAGEID = '3292'
22
+
23
+ desc "Publish the release files to RubyForge."
24
+ task :release => [:gem, :package] do
25
+ system("rubyforge login --username #{RUBY_FORGE_USER}")
26
+
27
+ gem = "pkg/#{PKG_FILE_NAME}.gem"
28
+ # -n notes/#{Maruku::Version}.txt
29
+ cmd = "rubyforge add_release %s %s \"%s\" %s" %
30
+ [RUBY_FORGE_GROUPID, RUBY_FORGE_PACKAGEID, RELEASE_NAME, gem]
31
+
32
+ puts cmd
33
+ system(cmd)
34
+
35
+ files = ["gem", "tgz", "zip"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
36
+ files.each do |file|
37
+ # system("rubyforge add_file %s %s %s %s" %
38
+ # [RUBY_FORGE_GROUPID, RUBY_FORGE_PACKAGEID, RELEASE_NAME, file])
39
+ end
40
+ end
41
+
42
+ task :test => [:markdown_span_tests, :markdown_block_tests]
43
+
44
+ task :markdown_block_tests do
45
+ tests = Dir['tests/unittest/**/*.md'].join(' ')
46
+ puts "Executing tests #{tests}"
47
+ # ok = marutest(tests)
48
+ ok = system "ruby -Ilib bin/marutest #{tests}"
49
+ raise "Failed block unittest" if not ok
50
+ end
51
+
52
+ task :markdown_span_tests do
53
+ ok = system( "ruby -Ilib lib/maruku/tests/new_parser.rb v b")
54
+ raise "Failed span unittest" if not ok
55
+ end
56
+
57
+ require 'rake/rdoctask'
58
+
59
+ Rake::RDocTask.new do |rdoc|
60
+ files = [#'README', 'LICENSE', 'COPYING',
61
+ 'lib/**/*.rb',
62
+ 'rdoc/*.rdoc'#, 'test/*.rb'
63
+ ]
64
+ rdoc.rdoc_files.add(files)
65
+ rdoc.main = "rdoc/main.rdoc" # page to start on
66
+ rdoc.title = "Maruku Documentation"
67
+ rdoc.template = "jamis.rb"
68
+ rdoc.rdoc_dir = 'doc' # rdoc output folder
69
+ rdoc.options << '--line-numbers' << '--inline-source'
70
+ end
71
+
72
+
73
+
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'maruku'
4
+
5
+ # If we are given filenames, convert each file
6
+ if not ARGV.empty?
7
+ ARGV.each do |f|
8
+ puts "Opening #{f}"
9
+
10
+ # read file content
11
+ input = File.open(f,'r').read
12
+
13
+ # create Maruku
14
+ doc = Maruku.new(input, {:on_error=>:warning})
15
+ # convert to a complete html document
16
+ output = doc.to_md
17
+
18
+ # write to file
19
+ dir = File.dirname(f)
20
+ filename = File.basename(f, File.extname(f)) + ".txt"
21
+
22
+ output = File.join(dir, filename)
23
+ File.open(output,'w') do |f| f.puts html end
24
+ end
25
+ else
26
+ # else, act as a filter
27
+ data = $stdin.read
28
+ puts Maruku.new(data, {:on_error=>:warning}).to_md
29
+ end
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'maruku'
4
+ require 'optparse'
5
+
6
+ def cli_puts(s)
7
+ $stderr.puts(s) if MaRuKu::Globals[:verbose]
8
+ end
9
+
10
+
11
+ export = :html
12
+ break_on_error = false
13
+ using_math = false
14
+ using_mathml = false
15
+ output_file = nil
16
+
17
+ opt = OptionParser.new do |opts|
18
+ opts.banner = "Usage: maruku [options] [file1.md [file2.md ..."
19
+
20
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
21
+ MaRuKu::Globals[:verbose] = v end
22
+ opts.on("-u", "--[no-]unsafe", "Use unsafe features") do |v|
23
+ MaRuKu::Globals[:unsafe_features] = v end
24
+
25
+ opts.on("-b", "Break on error") do |v|
26
+ break_on_error = true end
27
+
28
+
29
+ opts.on("-i", "--math-images ENGINE", "Uses ENGINE to render TeX to PNG.") do |s|
30
+ using_math = true
31
+ MaRuKu::Globals[:html_math_output_png] = true
32
+ MaRuKu::Globals[:html_math_output_mathml] = false
33
+ MaRuKu::Globals[:html_png_engine] = s
34
+ cli_puts "Using png engine #{s}."
35
+ end
36
+
37
+ opts.on("-m", "--math-engine ENGINE", "Uses ENGINE to render MathML") do |s|
38
+ MaRuKu::Globals[:html_math_output_png] = false
39
+ MaRuKu::Globals[:html_math_output_mathml] = true
40
+ using_math = true
41
+ using_mathml = true
42
+ MaRuKu::Globals[:html_math_engine] = s
43
+ end
44
+
45
+ opts.on("-o", "--output FILE", "Output filename") do |s|
46
+ output_file = s
47
+ end
48
+
49
+ opts.on_tail("--pdf", "Write PDF","First writes LaTeX, then calls pdflatex." ) do export = :pdf end
50
+ opts.on_tail("--s5", "Write S5 slideshow") do export = :s5 end
51
+ opts.on_tail("--html", "Write HTML") do export = :html end
52
+ opts.on_tail("--html-frag", "Write the contents of the BODY.") do export = :html_frag end
53
+ opts.on_tail("--tex", "Write LaTeX" ) do export = :tex end
54
+ opts.on_tail("--inspect", "Shows the parsing result" ) do export = :inspect end
55
+
56
+ opts.on_tail("--version", "Show version") do
57
+ puts "Maruku #{MaRuKu::Version}"; exit
58
+ end
59
+
60
+ opts.on_tail("-h", "--help", "Show this message") do
61
+ puts opts
62
+ exit
63
+ end
64
+
65
+ end
66
+
67
+ begin
68
+ opt.parse!
69
+ rescue OptionParser::InvalidOption=>e
70
+ $stderr.puts e
71
+ $stderr.puts opt
72
+ exit
73
+ end
74
+
75
+
76
+ if using_math
77
+ cli_puts "Using Math extensions."
78
+ require 'maruku/ext/math'
79
+ end
80
+
81
+ #p ARGV
82
+ #p MaRuKu::Globals
83
+
84
+
85
+ inputs =
86
+ # If we are given filenames, convert each file
87
+ if not ARGV.empty?
88
+ ARGV.map do |f|
89
+ # read file content
90
+ cli_puts "Reading from file #{f.inspect}."
91
+ [f, File.open(f,'r').read]
92
+ end
93
+ else
94
+ export = :html_frag if export == :html
95
+ export = :tex_frag if export == :tex
96
+
97
+ cli_puts "Reading from standard input."
98
+ [[nil, $stdin.read]]
99
+ end
100
+
101
+ inputs.each do |f, input|
102
+
103
+ # create Maruku
104
+ params = {}
105
+ params[:on_error] = break_on_error ? :raise : :warning
106
+
107
+ t = Time.now
108
+ doc = Maruku.new(input, params)
109
+
110
+ cli_puts ("Parsing in %.2f seconds." % (Time.now-t))
111
+
112
+ out=""; suffix = "?"
113
+ t = Time.now
114
+ case export
115
+ when :html
116
+ suffix = using_mathml ? '.xhtml' : '.html'
117
+ out = doc.to_html_document( {:indent => -1})
118
+ when :html_frag
119
+ suffix='.html_frag'
120
+ out = doc.to_html( {:indent => -1})
121
+ when :pdf, :tex
122
+ suffix='.tex'
123
+ out = doc.to_latex_document
124
+ when :tex_frag
125
+ suffix='.tex_frag'
126
+ out = doc.to_latex
127
+ when :inspect
128
+ suffix='.txt'
129
+ out = doc.inspect
130
+ when :markdown
131
+ suffix='.pretty_md'
132
+ out = doc.to_markdown
133
+ when :s5
134
+ suffix='_s5slides.xhtml'
135
+ out = doc.to_s5({:content_only => false})
136
+ end
137
+
138
+ cli_puts("Rendering in %.2f seconds." % (Time.now-t))
139
+
140
+ # write to file or stdout
141
+ if f
142
+
143
+ if not output_file
144
+ dir = File.dirname(f)
145
+ job = File.join(dir, File.basename(f, File.extname(f)))
146
+ output_file = job + suffix
147
+ else
148
+ job = File.basename(output_file, File.extname(output_file))
149
+ end
150
+
151
+ if output_file == "-"
152
+ cli_puts "Writing to standard output"
153
+ $stdout.puts out
154
+ else
155
+
156
+ if not (export == :pdf)
157
+ cli_puts "Writing to #{output_file}"
158
+ File.open(output_file,'w') do |f| f.puts out end
159
+ else
160
+ cli_puts "Writing to #{job}.tex"
161
+ File.open("#{job}.tex",'w') do |f| f.puts out end
162
+ cmd = "pdflatex '#{job}.tex' -interaction=nonstopmode "+
163
+ "'-output-directory=#{dir}' "
164
+ cli_puts "maruku: executing $ #{cmd}"
165
+ # run twice for cross references
166
+ system cmd
167
+ system cmd
168
+ end
169
+
170
+ end
171
+ else # write to stdout
172
+ cli_puts "Writing to standard output"
173
+ $stdout.puts out
174
+ end
175
+ end
176
+
@@ -0,0 +1,338 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'maruku'
4
+ require 'maruku/textile2'
5
+
6
+ $marutest_language = :markdown
7
+
8
+ #MARKER = "\n***EOF***\n"
9
+ SPLIT = %r{\n\*\*\*[^\*]+\*\*\*\n}m
10
+
11
+ def marker(x)
12
+ "\n*** Output of #{x} ***\n"
13
+ end
14
+
15
+ def write_lines(i, j, lines, prefix, i_star)
16
+ i = [i, 0].max
17
+ j = [j, lines.size-1].min
18
+ for a in i..j
19
+ l = lines[a].gsub(/\t/,' ')
20
+ puts( ("%s %3d" % [prefix, a]) +
21
+ (a==i_star ? " -->" : " ")+lines[a])
22
+ end
23
+ end
24
+
25
+ # a = expected b = found
26
+ def equals(a, b)
27
+ a = a.split("\n")
28
+ b = b.split("\n")
29
+
30
+ for i in 0..([a.size-1,b.size-1].max)
31
+ la = a[i]
32
+ lb = b[i]
33
+ if la != lb
34
+ puts "\n"
35
+
36
+
37
+ write_lines(i-3, i+3, a, "expected", i )
38
+ write_lines(i-3, i+3, b, " found", i )
39
+ return false
40
+ end
41
+ end
42
+ return true
43
+ end
44
+
45
+ TOTEST = [:inspect,:to_html,:to_latex,:to_md,:to_s]
46
+
47
+ def run_test(filename, its_ok, verbose=true)
48
+ # read file content
49
+ input = (f=File.open(filename,'r')).read; f.close
50
+
51
+ output_html = File.join(File.dirname(filename),
52
+ File.basename(filename, File.extname(filename)) + ".html")
53
+
54
+ # split the input in sections
55
+
56
+ stuff = input.split(SPLIT)
57
+ if stuff.size == 1
58
+ stuff[2] = stuff[0]
59
+ stuff[0] = "Write a comment here"
60
+ stuff[1] = "{} # params "
61
+ end
62
+
63
+ comment = stuff.shift
64
+ params_s = stuff.shift
65
+
66
+ params = eval(params_s||'{}')
67
+ if params == nil
68
+ raise "Null params? #{params_s.inspect}"
69
+ end
70
+
71
+ markdown = stuff.shift
72
+
73
+ # puts "comment: #{markdown.inspect}"
74
+ # puts "markdown: #{markdown.inspect}"
75
+
76
+ failed = []
77
+ relaxed = []
78
+ crashed = []
79
+ actual = {}
80
+
81
+ doc =
82
+ if $marutest_language == :markdown
83
+ Maruku.new(markdown, params)
84
+ else
85
+ MaRuKu.textile2(markdown, params)
86
+ end
87
+
88
+ for s in TOTEST
89
+ begin
90
+ if s==:to_html
91
+ actual[s] = doc.to_html
92
+ else
93
+ actual[s] = doc.send s
94
+ raise "Methods #{s} gave nil" if not actual[s]
95
+ end
96
+ rescue Exception => e
97
+ crashed << s
98
+ actual[s] = e.inspect+ "\n"+ e.backtrace.join("\n")
99
+ puts actual[s]
100
+ end
101
+ end
102
+
103
+ File.open(output_html, 'w') do |f|
104
+ f.write doc.to_html_document
105
+ end
106
+
107
+ begin
108
+ m = Maruku.new
109
+ d = m.instance_eval(actual[:inspect])
110
+ rescue Exception => e
111
+ s = e.inspect + e.backtrace.join("\n")
112
+ raise "Inspect is not correct:\n ========\n#{actual[:inspect]}"+
113
+ "============\n #{s}"
114
+ end
115
+
116
+ expected = {}
117
+ if (stuff.size < TOTEST.size)
118
+ $stdout.write " (first time!) "
119
+ TOTEST.each do |x| expected[x] = actual[x] end
120
+ else
121
+ TOTEST.each_index do |i|
122
+ symbol = TOTEST[i]
123
+ expected[symbol] = stuff[i]
124
+ # puts "symbol: #{symbol.inspect} = #{stuff[i].inspect}"
125
+ end
126
+ end
127
+
128
+ m = Maruku.new
129
+
130
+
131
+ if not its_ok.include? :inspect
132
+ begin
133
+ d = m.instance_eval(expected[:inspect])
134
+ # puts "Eval: #{d.inspect}"
135
+ expected[:inspect] = d.inspect
136
+ rescue Exception => e
137
+ s = e.inspect + e.backtrace.join("\n")
138
+ raise "Cannot eval user-provided string:\n #{expected[:inspect].to_s}"+
139
+ "\n #{s}"
140
+ end
141
+ end
142
+
143
+ # m.instance_eval(actual[:inspect]) != m.instance_eval(expected[:inspect])
144
+
145
+ # actual[:inspect] = m.instance_eval(actual[:inspect])
146
+ # expected[:inspect] = m.instance_eval(expected[:inspect])
147
+
148
+
149
+ TOTEST.each do |x|
150
+ expected[x].strip!
151
+ actual[x].strip!
152
+ if not equals(expected[x], actual[x])
153
+ if its_ok.include? x
154
+ expected[x] = actual[x]
155
+ $stdout.write " relax:#{x} "
156
+ relaxed << x
157
+ else
158
+ actual[x] = "-----| WARNING | -----\n" + actual[x].to_s
159
+ failed << x
160
+ end
161
+ end
162
+ end
163
+
164
+ f = File.open(filename, 'w')
165
+
166
+ f.write comment
167
+ f.write "\n*** Parameters: ***\n"
168
+ f.write params_s
169
+ f.write "\n*** Markdown input: ***\n"
170
+ f.write markdown
171
+
172
+ TOTEST.each do |x|
173
+ f.write marker(x)
174
+ f.write expected[x]
175
+ end
176
+ f.write "\n*** EOF ***\n"
177
+
178
+ if not failed.empty? or not crashed.empty?
179
+
180
+ f.puts "\n\n\n\nFailed tests: #{failed.inspect} \n"
181
+
182
+ TOTEST.each do |x|
183
+ f.write marker(x)
184
+ f.write actual[x]
185
+ end
186
+
187
+ else
188
+ f.puts "\n\n\n\tOK!\n\n\n"
189
+ end
190
+
191
+
192
+ md_pl = markdown_pl(markdown)
193
+
194
+ f.write "\n*** Output of Markdown.pl ***\n"
195
+ f.write md_pl
196
+
197
+ f.write "\n*** Output of Markdown.pl (parsed) ***\n"
198
+ begin
199
+ doc = REXML::Document.new("<div>#{md_pl}</div>",{
200
+ :compress_whitespace=>['div','p'],
201
+ :ignore_whitespace_nodes=>['div','p'],
202
+ :respect_whitespace=>['pre','code']
203
+ })
204
+ div = doc.root
205
+ xml =""
206
+ div.write_children(xml,indent=1,transitive=true,ie_hack=false)
207
+ f.write xml
208
+ rescue Exception=>e
209
+ f.puts "Error: #{e.inspect}"
210
+ end
211
+ f.close
212
+
213
+
214
+ return failed, relaxed, crashed
215
+ end
216
+
217
+ def markdown_pl(markdown)
218
+ tmp1 = "/tmp/marutest1"
219
+ tmp2 = "/tmp/marutest2"
220
+ File.open(tmp1,'w') do |f| f.puts markdown end
221
+ system "Markdown.pl < #{tmp1} > #{tmp2}"
222
+ f = File.open(tmp2,'r')
223
+ s = f.read
224
+ f.close
225
+ s
226
+ end
227
+
228
+ def passed?(args, arg)
229
+ if args.include? arg
230
+ args.delete arg
231
+ true
232
+ else
233
+ false
234
+ end
235
+ end
236
+
237
+ def marutest(args)
238
+ dont_worry = []
239
+ TOTEST.each do |x|
240
+ arg = "ok:#{x}"
241
+ # puts arg
242
+ if passed?(args, arg)
243
+ dont_worry << x
244
+ end
245
+ end
246
+
247
+ if passed?(args, 'ok')
248
+ dont_worry = TOTEST.clone
249
+ end
250
+
251
+ if dont_worry.size > 0
252
+ puts "Relaxed on #{dont_worry.inspect}"
253
+ end
254
+
255
+
256
+ failed = {}
257
+ relaxed = {}
258
+
259
+ args.each do |f|
260
+ $stdout.write f + ' '*(50-f.size) + " "
261
+ $stdout.flush
262
+ tf, tr, tcrashed = run_test(f, dont_worry)
263
+
264
+ tf = tf + tcrashed
265
+
266
+
267
+ if tr.size > 0
268
+ $stdout.write " relax #{tr.inspect} "
269
+ end
270
+
271
+ if tf.size>0
272
+ $stdout.write " failed on #{tf.inspect} "
273
+ else
274
+ $stdout.write " OK "
275
+ end
276
+
277
+ if tcrashed.size > 0
278
+ $stdout.write " CRASHED on #{tcrashed.inspect}"
279
+ end
280
+
281
+ $stdout.write "\n"
282
+
283
+ failed[f] = tf
284
+ relaxed[f] = tr
285
+ end
286
+
287
+ num_failed = 0
288
+ failed_cat = {}
289
+
290
+ puts "\n\n\n**** FINAL REPORT ****\n\n"
291
+
292
+
293
+ if failed.size > 0
294
+ failed.each do |file, fl|
295
+ num_failed += fl.size
296
+ if fl.size > 0
297
+ puts "\t#{file}\tfailed on #{fl.inspect}"
298
+ end
299
+ fl.each do |x|
300
+ failed_cat[x] = failed_cat[x] || 0
301
+ failed_cat[x] = failed_cat[x] + 1
302
+ end
303
+ end
304
+ end
305
+
306
+ if dont_worry.size > 0
307
+ puts "Relaxed on #{dont_worry.inspect}"
308
+ end
309
+
310
+ if relaxed.size > 0
311
+ relaxed.each do |file, r|
312
+ if r.size > 0
313
+ puts "\t#{file}\t\trelaxed on #{r.inspect}"
314
+ end
315
+ end
316
+ end
317
+
318
+ if failed_cat.size > 0
319
+ puts "\nCategories:\n"
320
+
321
+ failed_cat.each do |x, num|
322
+ puts "\t#{x.inspect} \tfailed #{num}/#{args.size}"
323
+ end
324
+ end
325
+
326
+ return num_failed == 0
327
+ end
328
+
329
+ if File.basename(__FILE__) == 'marutest'
330
+ if ARGV.empty?
331
+ puts "marutest is a tool for running Maruku's unittest."
332
+ exit 1
333
+ end
334
+ ok = marutest(ARGV.clone)
335
+
336
+ exit ok ? 0 : -1
337
+ end
338
+