maruku 0.2.13 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/bin/maruku +23 -15
  2. data/bin/maruku0.3 +37 -0
  3. data/bin/marutest +277 -0
  4. data/docs/changelog-0.3.html +99 -0
  5. data/docs/changelog-0.3.md +84 -0
  6. data/docs/faq.html +46 -0
  7. data/docs/faq.md +32 -0
  8. data/docs/index.html +629 -64
  9. data/docs/markdown_extra2.html +67 -14
  10. data/docs/markdown_syntax.html +631 -94
  11. data/docs/markdown_syntax_2.html +152 -0
  12. data/docs/maruku.html +629 -64
  13. data/docs/maruku.md +108 -105
  14. data/docs/proposal.html +362 -55
  15. data/docs/proposal.md +133 -169
  16. data/docs/todo.html +30 -0
  17. data/lib/maruku.rb +13 -3
  18. data/lib/maruku/errors_management.rb +75 -0
  19. data/lib/maruku/helpers.rb +164 -0
  20. data/lib/maruku/html_helper.rb +33 -13
  21. data/lib/maruku/parse_block.rb +89 -92
  22. data/lib/maruku/parse_doc.rb +43 -18
  23. data/lib/maruku/parse_span.rb +17 -46
  24. data/lib/maruku/parse_span_better.rb +681 -0
  25. data/lib/maruku/string_utils.rb +17 -10
  26. data/lib/maruku/structures.rb +62 -35
  27. data/lib/maruku/structures_iterators.rb +39 -0
  28. data/lib/maruku/tests/benchmark.rb +12 -4
  29. data/lib/maruku/tests/new_parser.rb +318 -0
  30. data/lib/maruku/to_html.rb +113 -44
  31. data/lib/maruku/to_latex.rb +32 -14
  32. data/lib/maruku/to_markdown.rb +110 -0
  33. data/lib/maruku/toc.rb +35 -1
  34. data/lib/maruku/version.rb +10 -1
  35. data/lib/test.rb +29 -0
  36. data/tests/others/escaping.md +6 -4
  37. data/tests/others/links.md +1 -1
  38. data/tests/others/lists_after_paragraph.md +44 -0
  39. data/tests/unittest/abbreviations.md +71 -0
  40. data/tests/unittest/blank.md +43 -0
  41. data/tests/unittest/blanks_in_code.md +131 -0
  42. data/tests/unittest/code.md +64 -0
  43. data/tests/unittest/code2.md +59 -0
  44. data/tests/unittest/code3.md +121 -0
  45. data/tests/unittest/easy.md +36 -0
  46. data/tests/unittest/email.md +39 -0
  47. data/tests/unittest/encoding/iso-8859-1.md +9 -0
  48. data/tests/unittest/encoding/utf-8.md +38 -0
  49. data/tests/unittest/entities.md +174 -0
  50. data/tests/unittest/escaping.md +97 -0
  51. data/tests/unittest/extra_dl.md +81 -0
  52. data/tests/unittest/extra_header_id.md +96 -0
  53. data/tests/unittest/extra_table1.md +78 -0
  54. data/tests/unittest/footnotes.md +120 -0
  55. data/tests/unittest/headers.md +64 -0
  56. data/tests/unittest/hrule.md +77 -0
  57. data/tests/unittest/images.md +114 -0
  58. data/tests/unittest/inline_html.md +185 -0
  59. data/tests/unittest/links.md +162 -0
  60. data/tests/unittest/list1.md +80 -0
  61. data/tests/unittest/list2.md +75 -0
  62. data/tests/unittest/list3.md +111 -0
  63. data/tests/unittest/list4.md +43 -0
  64. data/tests/unittest/lists.md +262 -0
  65. data/tests/unittest/lists_after_paragraph.md +280 -0
  66. data/tests/unittest/lists_ol.md +323 -0
  67. data/tests/unittest/misc_sw.md +751 -0
  68. data/tests/unittest/notyet/escape.md +46 -0
  69. data/tests/unittest/notyet/header_after_par.md +85 -0
  70. data/tests/unittest/notyet/ticks.md +67 -0
  71. data/tests/unittest/notyet/triggering.md +210 -0
  72. data/tests/unittest/one.md +33 -0
  73. data/tests/unittest/paragraph.md +34 -0
  74. data/tests/unittest/paragraph_rules/dont_merge_ref.md +60 -0
  75. data/tests/unittest/paragraph_rules/tab_is_blank.md +43 -0
  76. data/tests/unittest/paragraphs.md +84 -0
  77. data/tests/unittest/recover/recover_links.md +32 -0
  78. data/tests/unittest/references/long_example.md +87 -0
  79. data/tests/unittest/references/spaces_and_numbers.md +27 -0
  80. data/tests/unittest/syntax_hl.md +99 -0
  81. data/tests/unittest/test.md +36 -0
  82. data/tests/unittest/wrapping.md +88 -0
  83. data/tests/utf8-files/simple.md +1 -0
  84. metadata +139 -86
  85. data/lib/maruku/maruku.rb +0 -50
  86. data/tests/a.md +0 -10
data/bin/maruku CHANGED
@@ -3,23 +3,31 @@
3
3
  require 'maruku'
4
4
 
5
5
  if File.basename($0) =~ /^maruku/
6
- # Convert each file
7
- ARGV.each do |f|
8
- puts "Opening #{f}"
6
+ # If we are given filenames, convert each file
7
+ if not ARGV.empty?
8
+ ARGV.each do |f|
9
+ puts "Opening #{f}"
9
10
 
10
- # read file content
11
- input = File.open(f,'r').read
11
+ # read file content
12
+ input = File.open(f,'r').read
12
13
 
13
- # create Maruku
14
- doc = Maruku.new(input)
15
- # convert to a complete html document
16
- html = doc.to_html_document
14
+ # create Maruku
15
+ doc = Maruku.new(input, {:on_error=>:warning})
16
+ # convert to a complete html document
17
+ html = doc.to_html_document( {:indent => -1})
17
18
 
18
- # write to file
19
- dir = File.dirname(f)
20
- filename = File.basename(f, File.extname(f)) + ".html"
19
+ # write to file
20
+ dir = File.dirname(f)
21
+ filename = File.basename(f, File.extname(f)) + ".html"
21
22
 
22
- out_xml = File.join(dir, filename)
23
- File.open(out_xml,'w') do |f| f.puts html end
23
+ out_xml = File.join(dir, filename)
24
+ File.open(out_xml,'w') do |f| f.puts html end
25
+ end
26
+ else
27
+ # else, act as a filter
28
+ data = $stdin.read
29
+ puts Maruku.new(data).to_html
24
30
  end
25
- end
31
+ end
32
+
33
+
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'maruku'
4
+
5
+ require 'maruku/parse_span_better'
6
+
7
+ #if File.basename($0) =~ /^maruku/
8
+ # If we are given filenames, convert each file
9
+ if not ARGV.empty?
10
+ ARGV.each do |f|
11
+ puts "Opening #{f}"
12
+
13
+ # read file content
14
+ input = File.open(f,'r').read
15
+
16
+ # create Maruku
17
+ doc = Maruku.new(input)
18
+
19
+ # puts doc.inspect
20
+ # convert to a complete html document
21
+ html = doc.to_html_document({:indent=>1})
22
+
23
+ # write to file
24
+ dir = File.dirname(f)
25
+ filename = File.basename(f, File.extname(f)) + ".html"
26
+
27
+ out_xml = File.join(dir, filename)
28
+ File.open(out_xml,'w') do |f| f.puts html end
29
+ end
30
+ else
31
+ # else, act as a filter
32
+ data = $stdin.read
33
+ puts Maruku.new(data).to_html
34
+ end
35
+ #eend
36
+
37
+
@@ -0,0 +1,277 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'maruku'
4
+
5
+ require 'maruku/parse_span_better'
6
+
7
+ #MARKER = "\n***EOF***\n"
8
+ SPLIT = %r{\n\*\*\*[^\*]+\*\*\*\n}m
9
+
10
+ def marker(x)
11
+ "\n*** Output of #{x} ***\n"
12
+ end
13
+
14
+ TOTEST = [:inspect,:to_html,:to_latex,:to_s,:to_s]
15
+
16
+ def run_test(filename, its_ok, verbose=true)
17
+ # read file content
18
+ input = (f=File.open(filename,'r')).read; f.close
19
+
20
+ # split the input in sections
21
+
22
+ stuff = input.split(SPLIT)
23
+
24
+ comment = stuff.shift
25
+ params_s = stuff.shift
26
+
27
+ params = eval(params_s)
28
+ if params == nil
29
+ raise "Null params? #{params_s.inspect}"
30
+ end
31
+
32
+ markdown = stuff.shift
33
+
34
+ # puts "comment: #{markdown.inspect}"
35
+ # puts "markdown: #{markdown.inspect}"
36
+
37
+ failed = []
38
+ relaxed = []
39
+ crashed = []
40
+ actual = {}
41
+
42
+ doc = Maruku.new(markdown, params)
43
+
44
+ for s in TOTEST
45
+ begin
46
+ if s==:to_html
47
+ actual[s] = doc.to_html
48
+ else
49
+ actual[s] = doc.send s
50
+ raise "Methods #{s} gave nil" if not actual[s]
51
+ end
52
+ rescue Exception => e
53
+ crashed << s
54
+ actual[s] = e.inspect+ "\n"+ e.backtrace.join("\n")
55
+ puts actual[s]
56
+ end
57
+ end
58
+
59
+
60
+ begin
61
+ m = Maruku.new
62
+ d = m.instance_eval(actual[:inspect])
63
+ rescue Exception => e
64
+ s = e.inspect + e.backtrace.join("\n")
65
+ raise "Inspect is not correct:\n ========\n#{actual[:inspect]}"+
66
+ "============\n #{s}"
67
+ end
68
+
69
+ expected = {}
70
+ if (stuff.size < TOTEST.size)
71
+ $stdout.write " (first time!) "
72
+ TOTEST.each do |x| expected[x] = actual[x] end
73
+ else
74
+ TOTEST.each_index do |i|
75
+ symbol = TOTEST[i]
76
+ expected[symbol] = stuff[i]
77
+ # puts "symbol: #{symbol.inspect} = #{stuff[i].inspect}"
78
+ end
79
+ end
80
+
81
+ if not its_ok.include? :inspect
82
+ begin
83
+ m = Maruku.new
84
+ d = m.instance_eval(expected[:inspect])
85
+ # puts "Eval: #{d.inspect}"
86
+ expected[:inspect] = d.inspect
87
+ rescue Exception => e
88
+ s = e.inspect + e.backtrace.join("\n")
89
+ raise "Cannot eval user-provided string:\n #{expected[:inspect].to_s}"+
90
+ "\n #{s}"
91
+ end
92
+ end
93
+
94
+
95
+ TOTEST.each do |x|
96
+ if actual[x] != expected[x]
97
+ if its_ok.include? x
98
+ expected[x] = actual[x]
99
+ $stdout.write " relax:#{x} "
100
+ relaxed << x
101
+ else
102
+ actual[x] = "-----| WARNING | -----\n" + actual[x]
103
+ failed << x
104
+ end
105
+ end
106
+ end
107
+
108
+ f = File.open(filename, 'w')
109
+
110
+ f.write comment
111
+ f.write "\n*** Parameters: ***\n"
112
+ f.write params.inspect
113
+ f.write "\n*** Markdown input: ***\n"
114
+ f.write markdown
115
+
116
+ TOTEST.each do |x|
117
+ f.write marker(x)
118
+ f.write expected[x]
119
+ end
120
+ f.write "\n*** EOF ***\n"
121
+
122
+ if not failed.empty? or not crashed.empty?
123
+
124
+ f.puts "\n\n\n\nFailed tests: #{failed.inspect} \n"
125
+
126
+ TOTEST.each do |x|
127
+ f.write marker(x)
128
+ f.write actual[x]
129
+ end
130
+
131
+ else
132
+ f.puts "\n\n\n\tOK!\n\n\n"
133
+ end
134
+
135
+
136
+ md_pl = markdown_pl(markdown)
137
+
138
+ f.write "\n*** Output of Markdown.pl ***\n"
139
+ f.write md_pl
140
+
141
+ f.write "\n*** Output of Markdown.pl (parsed) ***\n"
142
+ begin
143
+ doc = REXML::Document.new("<div>#{md_pl}</div>",{
144
+ :compress_whitespace=>['div','p'],
145
+ :ignore_whitespace_nodes=>['div','p'],
146
+ :respect_whitespace=>['pre','code']
147
+ })
148
+ div = doc.root
149
+ xml =""
150
+ div.write_children(xml,indent=1,transitive=true,ie_hack=false)
151
+ f.write xml
152
+ rescue Exception=>e
153
+ f.puts "Error: #{e.inspect}"
154
+ end
155
+ f.close
156
+
157
+
158
+ return failed, relaxed, crashed
159
+ end
160
+
161
+ def markdown_pl(markdown)
162
+ tmp1 = "/tmp/marutest1"
163
+ tmp2 = "/tmp/marutest2"
164
+ File.open(tmp1,'w') do |f| f.puts markdown end
165
+ system "Markdown.pl < #{tmp1} > #{tmp2}"
166
+ f = File.open(tmp2,'r')
167
+ s = f.read
168
+ f.close
169
+ s
170
+ end
171
+
172
+ def passed?(args, arg)
173
+ if args.include? arg
174
+ args.delete arg
175
+ true
176
+ else
177
+ false
178
+ end
179
+ end
180
+
181
+ def marutest
182
+ args = ARGV.clone
183
+
184
+ dont_worry = []
185
+ TOTEST.each do |x|
186
+ arg = "ok:#{x}"
187
+ # puts arg
188
+ if passed?(args, arg)
189
+ dont_worry << x
190
+ end
191
+ end
192
+
193
+ if passed?(args, 'ok')
194
+ dont_worry = TOTEST.clone
195
+ end
196
+
197
+ if dont_worry.size > 0
198
+ puts "Relaxed on #{dont_worry.inspect}"
199
+ end
200
+
201
+
202
+ failed = {}
203
+ relaxed = {}
204
+
205
+ args.each do |f|
206
+ $stdout.write "#{f}\n\t\t"
207
+ tf, tr, tcrashed = run_test(f, dont_worry)
208
+
209
+ tf = tf + tcrashed
210
+
211
+
212
+ if tr.size > 0
213
+ $stdout.write " relax #{tr.inspect} "
214
+ end
215
+
216
+ if tf.size>0
217
+ $stdout.write " failed on #{tf.inspect} "
218
+ else
219
+ $stdout.write " OK "
220
+ end
221
+
222
+ if tcrashed.size > 0
223
+ $stdout.write " CRASHED on #{tcrashed.inspect}"
224
+ end
225
+
226
+ $stdout.write "\n"
227
+
228
+ failed[f] = tf
229
+ relaxed[f] = tr
230
+ end
231
+
232
+ num_failed = 0
233
+ failed_cat = {}
234
+
235
+ puts "\n\n\n**** FINAL REPORT ****\n\n"
236
+
237
+
238
+ if failed.size > 0
239
+ failed.each do |file, fl|
240
+ num_failed += failed.size
241
+ if fl.size > 0
242
+ puts "\t#{file}\tfailed on #{fl.inspect}"
243
+ end
244
+ fl.each do |x|
245
+ failed_cat[x] = failed_cat[x] || 0
246
+ failed_cat[x] = failed_cat[x] + 1
247
+ end
248
+ end
249
+ end
250
+
251
+ if dont_worry.size > 0
252
+ puts "Relaxed on #{dont_worry.inspect}"
253
+ end
254
+
255
+ if relaxed.size > 0
256
+ relaxed.each do |file, r|
257
+ if r.size > 0
258
+ puts "\t#{file}\t\trelaxed on #{r.inspect}"
259
+ end
260
+ end
261
+ end
262
+
263
+ if failed_cat.size > 0
264
+ puts "\nCategories:\n"
265
+
266
+ failed_cat.each do |x, num|
267
+ puts "\t#{x.inspect} \tfailed #{num}/#{args.size}"
268
+ end
269
+ end
270
+
271
+ num_failed
272
+ end
273
+
274
+
275
+ marutest
276
+
277
+
@@ -0,0 +1,99 @@
1
+ <?xml version='1.0' encoding='utf-8'?>
2
+ <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
3
+ 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
4
+ <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
5
+ <head>
6
+ <title></title>
7
+
8
+ <link href='style.css' rel='stylesheet' type='text/css' />
9
+ </head>
10
+ <body>
11
+ <h2 id='release_notes__version_030_january_3rd_2007'>Release notes - version 0.3.0 (January 3rd, 2007)</h2>
12
+
13
+ <p>Note: Maruku seems to be very robust, nevertheless it is still beta-level software. So if you want to use it in production environments, please check back in a month or so, while we squash the remaining bugs.</p>
14
+
15
+ <p>In the meantime, feel free to toy around, and please signal problems, request features, by <a href='http://www.dis.uniroma1.it/~acensi/contact.html'>contacting me</a> or using the <a href='http://rubyforge.org/tracker/?group_id=2795'>tracker</a>. For issues about the Markdown syntax itself and improvements to it, please write to the <a href='http://six.pairlist.net/mailman/listinfo/markdown-discuss'>Markdown-discuss mailing list</a>.</p>
16
+
17
+ <p>Have fun!</p>
18
+
19
+ <p>Changes in 0.3.0:</p>
20
+
21
+ <ul>
22
+ <li>
23
+ <p>A real parser is used instead of a regexp-based system, also for span-level elements..</p>
24
+
25
+ <p>Now Maruku is almost 2x faster than Bluecloth, while having more features.</p>
26
+
27
+ <p>Here are some benchmarks:</p>
28
+
29
+ <pre><code>BlueCloth (to_html): parsing 0.00 sec + rendering 1.54 sec = 1.55 sec
30
+ Maruku (to_html): parsing 0.47 sec + rendering 0.38 sec = 0.85 sec
31
+ Maruku (to_latex): parsing 0.49 sec + rendering 0.25 sec = 0.73 sec</code></pre>
32
+
33
+ <p>This is the result of running <code>lib/maruku/tests/benchmark.rb</code> on the Markdown specification.</p>
34
+ </li>
35
+
36
+ <li>
37
+ <p>Prettier HTML output by adding whitespace.</p>
38
+ </li>
39
+
40
+ <li>
41
+ <p>Added a full suite of unit-tests for the span-level parser.</p>
42
+ </li>
43
+
44
+ <li>
45
+ <p>Error management: Having a real parser, Maruku warns you about syntax issues.</p>
46
+
47
+ <p>The default action is to warn and try to continue. If you do this:</p>
48
+
49
+ <pre><code>Maruku.new(string, {:on_error =&gt; :raise})
50
+ </code></pre>
51
+
52
+ <p>then syntax errors will cause an exception to be raised (you can catch this and retry).</p>
53
+ </li>
54
+
55
+ <li>
56
+ <p>Fixed a series of bugs in handling inline HTML code.</p>
57
+ </li>
58
+ </ul>
59
+
60
+ <p>Immediate TODO-list:</p>
61
+
62
+ <ul>
63
+ <li>
64
+ <p>UTF-8 input/output works OK for HTML, however I am having pain trying to export to LaTeX. I want at least Japanese characters support, so if you know how to do this you are very welcome to give me an hand.</p>
65
+
66
+ <p>For example: in the HTML version, you should see accented characters in this parenthesis: </p>
67
+
68
+ <blockquote>
69
+ <p>(àèìòù)</p>
70
+ </blockquote>
71
+
72
+ <p>and Japanese text in these other parenthesis: </p>
73
+
74
+ <blockquote>
75
+ <p>(カタカナで 私の 名前は アンドレア チェンシ です).</p>
76
+
77
+ <p>(日本のガルは 大好き、でも、日本語は難しですから、そうぞ 英語話すガルを おしえてください).</p>
78
+ </blockquote>
79
+
80
+ <p>In the LaTeX version, these do not appear. I know how to do LaTeX with ISO-8859-1 encoding (European characters), but I&apos;m struggling with half-baked solutions for UTF-8 encoded documents.</p>
81
+ </li>
82
+
83
+ <li>
84
+ <p>Implement the <a href='http://maruku.rubyforge.org/'>new meta-data proposal</a>.</p>
85
+ </li>
86
+
87
+ <li>
88
+ <p>Exporting to Markdown (pretty printing).</p>
89
+ </li>
90
+
91
+ <li>
92
+ <p>Exporting to HTML splitting in multiple files.</p>
93
+ </li>
94
+ </ul>
95
+
96
+ <div class='maruku_signature'>
97
+ <hr />
98
+ <span style='font-size: small; font-style: italic'>Created by <a href='http://maruku.rubyforge.org' title='Maruku: a Markdown interpreter'>Maruku</a> at 00:06 on Wednesday, January 03rd, 2007.</span></div>
99
+ </body></html>