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,61 @@
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
+ # Yields to each element of specified node_type
27
+ # All elements if e_node_type is nil.
28
+ def each_element(e_node_type=nil, &block)
29
+ @children.each do |c|
30
+ if c.kind_of? MDElement
31
+ if (not e_node_type) || (e_node_type == c.node_type)
32
+ block.call c
33
+ end
34
+ c.each_element(e_node_type, &block)
35
+ end
36
+ end
37
+ end
38
+
39
+ # Apply passed block to each String in the hierarchy.
40
+ def replace_each_string(&block)
41
+ for c in @children
42
+ if c.kind_of? MDElement
43
+ c.replace_each_string(&block)
44
+ end
45
+ end
46
+
47
+ processed = []
48
+ until @children.empty?
49
+ c = @children.shift
50
+ if c.kind_of? String
51
+ result = block.call(c)
52
+ [*result].each do |e| processed << e end
53
+ else
54
+ processed << c
55
+ end
56
+ end
57
+ @children = processed
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,82 @@
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
+ require 'maruku'
23
+ #require 'bluecloth'
24
+
25
+
26
+ data = $stdin.read
27
+
28
+ num = 10
29
+
30
+ if ARGV.size > 0 && ((n=ARGV[0].to_i) != 0)
31
+ num = n
32
+ end
33
+
34
+ methods =
35
+ [
36
+
37
+ [Maruku, :to_html],
38
+ # [BlueCloth, :to_html],
39
+ [Maruku, :to_latex]
40
+
41
+ ]
42
+
43
+ #methods = [[Maruku, :class]]
44
+ #num = 10
45
+
46
+ stats =
47
+ methods .map do |c, method|
48
+ puts "Computing for #{c}"
49
+
50
+ start = Time.now
51
+ doc = nil
52
+ for i in 1..num
53
+ $stdout.write "#{i} "; $stdout.flush
54
+ doc = c.new(data)
55
+ end
56
+ stop = Time.now
57
+ parsing = (stop-start)/num
58
+
59
+ start = Time.now
60
+ for i in 1..num
61
+ $stdout.write "#{i} "; $stdout.flush
62
+ s = doc.send method
63
+ end
64
+ stop = Time.now
65
+ rendering = (stop-start)/num
66
+
67
+ puts ("%s (%s): parsing %0.2f sec + rendering %0.2f sec "+
68
+ "= %0.2f sec ") % [c, method, parsing,rendering,parsing+rendering]
69
+
70
+ [c, method, parsing, rendering]
71
+ end
72
+
73
+ puts "\n\n\n"
74
+ stats.each do |x| x.push(x[2]+x[3]) end
75
+ max = stats.map{|x|x[4]}.max
76
+ stats.sort! { |x,y| x[4] <=> y[4] } . reverse!
77
+ for c, method, parsing, rendering, tot in stats
78
+ puts ("%20s: parsing %0.2f sec + rendering %0.2f sec "+
79
+ "= %0.2f sec (%0.2fx)") %
80
+ ["#{c} (#{method})", parsing,rendering,tot,max/tot]
81
+ end
82
+
@@ -0,0 +1,370 @@
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
+ require 'maruku'
23
+ require 'maruku/ext/math'
24
+
25
+ module MaRuKu; module Tests
26
+ # 5 accented letters in italian, encoded as UTF-8
27
+ AccIta8 = "\303\240\303\250\303\254\303\262\303\271"
28
+
29
+ # Same letters, written in ISO-8859-1 (one byte per letter)
30
+ AccIta1 = "\340\350\354\362\371"
31
+
32
+ # The word MA-RU-KU, written in katakana using UTF-8
33
+ Maruku8 = "\343\203\236\343\203\253\343\202\257"
34
+
35
+ def test_span_parser(verbose, break_on_first_error, quiet)
36
+ good_cases = [
37
+
38
+ ["", [], 'Empty string gives empty list'],
39
+ ["a", ["a"], 'Easy char'],
40
+ [" a", ["a"], 'First space in the paragraph is ignored'],
41
+ ["a\n \n", ["a"], 'Last spaces in the paragraphs are ignored'],
42
+ [' ', [], 'One char => nothing'],
43
+ [' ', [], 'Two chars => nothing'],
44
+ ['a b', ['a b'], 'Spaces are compressed'],
45
+ ['a b', ['a b'], 'Newlines are spaces'],
46
+ ["a\nb", ['a b'], 'Newlines are spaces'],
47
+ ["a\n b", ['a b'], 'Compress newlines 1'],
48
+ ["a \nb", ['a b'], 'Compress newlines 2'],
49
+ [" \nb", ['b'], 'Compress newlines 3'],
50
+ ["\nb", ['b'], 'Compress newlines 4'],
51
+ ["b\n", ['b'], 'Compress newlines 5'],
52
+ ["\n", [], 'Compress newlines 6'],
53
+ ["\n\n\n", [], 'Compress newlines 7'],
54
+
55
+ [nil, :throw, "Should throw on nil input"],
56
+
57
+ # Code blocks
58
+ ["`" , :throw, 'Unclosed single ticks'],
59
+ ["``" , :throw, 'Unclosed double ticks'],
60
+ ["`a`" , [md_code('a')], 'Simple inline code'],
61
+ ["`` ` ``" , [md_code('`')], ],
62
+ ["`` \\` ``" , [md_code('\\`')], ],
63
+ ["``a``" , [md_code('a')], ],
64
+ ["`` a ``" , [md_code('a')], ],
65
+
66
+ # Newlines
67
+ ["a \n", ['a',md_el(:linebreak)], 'Two spaces give br.'],
68
+ ["a \n", ['a'], 'Newlines 2'],
69
+ [" \n", [md_el(:linebreak)], 'Newlines 3'],
70
+ [" \n \n", [md_el(:linebreak),md_el(:linebreak)],'Newlines 3'],
71
+ [" \na \n", [md_el(:linebreak),'a',md_el(:linebreak)],'Newlines 3'],
72
+
73
+ # Inline HTML
74
+ ["a < b", ['a < b'], '< can be on itself'],
75
+ ["<hr>", [md_html('<hr />')], 'HR will be sanitized'],
76
+ ["<hr/>", [md_html('<hr />')], 'Closed tag is ok'],
77
+ ["<hr />", [md_html('<hr />')], 'Closed tag is ok 2'],
78
+ ["<hr/>a", [md_html('<hr />'),'a'], 'Closed tag is ok 2'],
79
+ ["<em></em>a", [md_html('<em></em>'),'a'], 'Inline HTML 1'],
80
+ ["<em>e</em>a", [md_html('<em>e</em>'),'a'], 'Inline HTML 2'],
81
+ ["a<em>e</em>b", ['a',md_html('<em>e</em>'),'b'], 'Inline HTML 3'],
82
+ ["<em>e</em>a<em>f</em>",
83
+ [md_html('<em>e</em>'),'a',md_html('<em>f</em>')],
84
+ 'Inline HTML 4'],
85
+ ["<em>e</em><em>f</em>a",
86
+ [md_html('<em>e</em>'),md_html('<em>f</em>'),'a'],
87
+ 'Inline HTML 5'],
88
+
89
+ ["<img src='a' />", [md_html("<img src='a' />")], 'Attributes'],
90
+ ["<img src='a'/>"],
91
+
92
+ # emphasis
93
+ ["**", :throw, 'Unclosed double **'],
94
+ ["\\*", ['*'], 'Escaping of *'],
95
+ ["a *b* ", ['a ', md_em('b')], 'Emphasis 1'],
96
+ ["a *b*", ['a ', md_em('b')], 'Emphasis 2'],
97
+ ["a * b", ['a * b'], 'Emphasis 3'],
98
+ ["a * b*", :throw, 'Unclosed emphasis'],
99
+ # same with underscore
100
+ ["__", :throw, 'Unclosed double __'],
101
+ ["\\_", ['_'], 'Escaping of _'],
102
+ ["a _b_ ", ['a ', md_em('b')], 'Emphasis 4'],
103
+ ["a _b_", ['a ', md_em('b')], 'Emphasis 5'],
104
+ ["a _ b", ['a _ b'], 'Emphasis 6'],
105
+ ["a _ b_", :throw, 'Unclosed emphasis'],
106
+ ["_b_", [md_em('b')], 'Emphasis 7'],
107
+ ["_b_ _c_", [md_em('b'),' ',md_em('c')], 'Emphasis 8'],
108
+ ["_b__c_", [md_em('b'),md_em('c')], 'Emphasis 9'],
109
+ # strong
110
+ ["**a*", :throw, 'Unclosed double ** 2'],
111
+ ["\\**a*", ['*', md_em('a')], 'Escaping of *'],
112
+ ["a **b** ", ['a ', md_strong('b')], 'Emphasis 1'],
113
+ ["a **b**", ['a ', md_strong('b')], 'Emphasis 2'],
114
+ ["a ** b", ['a ** b'], 'Emphasis 3'],
115
+ ["a ** b**", :throw, 'Unclosed emphasis'],
116
+ ["**b****c**", [md_strong('b'),md_strong('c')], 'Emphasis 9'],
117
+ # strong (with underscore)
118
+ ["__a_", :throw, 'Unclosed double __ 2'],
119
+ ["\\__a_", ['_', md_em('a')], 'Escaping of _'],
120
+ ["a __b__ ", ['a ', md_strong('b')], 'Emphasis 1'],
121
+ ["a __b__", ['a ', md_strong('b')], 'Emphasis 2'],
122
+ ["a __ b", ['a __ b'], 'Emphasis 3'],
123
+ ["a __ b__", :throw, 'Unclosed emphasis'],
124
+ ["__b____c__", [md_strong('b'),md_strong('c')], 'Emphasis 9'],
125
+ # extra strong
126
+ ["***a**", :throw, 'Unclosed triple *** '],
127
+ ["\\***a**", ['*', md_strong('a')], 'Escaping of *'],
128
+ ["a ***b*** ", ['a ', md_emstrong('b')], 'Strong elements'],
129
+ ["a ***b***", ['a ', md_emstrong('b')]],
130
+ ["a *** b", ['a *** b']],
131
+ ["a ** * b", ['a ** * b']],
132
+ ["***b******c***", [md_emstrong('b'),md_emstrong('c')]],
133
+ ["a *** b***", :throw, 'Unclosed emphasis'],
134
+ # same with underscores
135
+ ["___a__", :throw, 'Unclosed triple *** '],
136
+ ["\\___a__", ['_', md_strong('a')], 'Escaping of *'],
137
+ ["a ___b___ ", ['a ', md_emstrong('b')], 'Strong elements'],
138
+ ["a ___b___", ['a ', md_emstrong('b')]],
139
+ ["a ___ b", ['a ___ b']],
140
+ ["a __ _ b", ['a __ _ b']],
141
+ ["___b______c___", [md_emstrong('b'),md_emstrong('c')]],
142
+ ["a ___ b___", :throw, 'Unclosed emphasis'],
143
+ # mixing is bad
144
+ ["*a_", :throw, 'Mixing is bad'],
145
+ ["_a*", :throw],
146
+ ["**a__", :throw],
147
+ ["__a**", :throw],
148
+ ["___a***", :throw],
149
+ ["***a___", :throw],
150
+ # links of the form [text][ref]
151
+ ["\\[a]", ["[a]"], 'Escaping 1'],
152
+ ["\\[a\\]", ["[a]"], 'Escaping 2'],
153
+ # This is valid in the new Markdown version
154
+ # ["[a]", ["a"], 'Not a link'],
155
+ ["[a]", [ md_link(["a"],'a')], 'Empty link'],
156
+ ["[a][]", ],
157
+ ["[a][]b", [ md_link(["a"],'a'),'b'], 'Empty link'],
158
+ ["[a\\]][]", [ md_link(["a]"],'a')], 'Escape inside link (throw ?] away)'],
159
+
160
+ ["[a", :throw, 'Link not closed'],
161
+ ["[a][", :throw, 'Ref not closed'],
162
+
163
+ # links of the form [text](url)
164
+ ["\\[a](b)", ["[a](b)"], 'Links'],
165
+ ["[a](url)c", [md_im_link(['a'],'url'),'c'], 'url'],
166
+ ["[a]( url )c" ],
167
+ ["[a] ( url )c" ],
168
+ ["[a] ( url)c" ],
169
+
170
+ ["[a](ur:/l/ 'Title')", [md_im_link(['a'],'ur:/l/','Title')],
171
+ 'url and title'],
172
+ ["[a] ( ur:/l/ \"Title\")" ],
173
+ ["[a] ( ur:/l/ \"Title\")" ],
174
+ ["[a]( ur:/l/ Title)", :throw, "Must quote title" ],
175
+
176
+ ["[a](url 'Tit\\\"l\\\\e')", [md_im_link(['a'],'url','Tit"l\\e')],
177
+ 'url and title escaped'],
178
+ ["[a] ( url \"Tit\\\"l\\\\e\")" ],
179
+ ["[a] ( url \"Tit\\\"l\\\\e\" )" ],
180
+ ['[a] ( url "Tit\\"l\\\\e" )' ],
181
+ ["[a]()", [md_im_link(['a'],'')], 'No URL is OK'],
182
+
183
+ ["[a](\"Title\")", :throw, "No url specified" ],
184
+ ["[a](url \"Title)", :throw, "Unclosed quotes" ],
185
+ ["[a](url \"Title\\\")", :throw],
186
+ ["[a](url \"Title\" ", :throw],
187
+
188
+ ["[a](url \'Title\")", :throw, "Mixing is bad" ],
189
+ ["[a](url \"Title\')"],
190
+
191
+ ["[a](/url)", [md_im_link(['a'],'/url')], 'Funny chars in url'],
192
+ ["[a](#url)", [md_im_link(['a'],'#url')]],
193
+ ["[a](</script?foo=1&bar=2>)", [md_im_link(['a'],'/script?foo=1&bar=2')]],
194
+
195
+
196
+ # Images
197
+ ["\\![a](url)", ['!', md_im_link(['a'],'url') ], 'Escaping images'],
198
+
199
+ ["![a](url)", [md_im_image(['a'],'url')], 'Image no title'],
200
+ ["![a]( url )" ],
201
+ ["![a] ( url )" ],
202
+ ["![a] ( url)" ],
203
+
204
+ ["![a](url 'ti\"tle')", [md_im_image(['a'],'url','ti"tle')], 'Image with title'],
205
+ ['![a]( url "ti\\"tle")' ],
206
+
207
+ ["![a](url", :throw, 'Invalid images'],
208
+ ["![a( url )" ],
209
+ ["![a] ('url )" ],
210
+
211
+ ["![a][imref]", [md_image(['a'],'imref')], 'Image with ref'],
212
+ ["![a][ imref]"],
213
+ ["![a][ imref ]"],
214
+ ["![a][\timref\t]"],
215
+
216
+
217
+ ['<http://example.com/?foo=1&bar=2>',
218
+ [md_url('http://example.com/?foo=1&bar=2')], 'Immediate link'],
219
+ ['a<http://example.com/?foo=1&bar=2>b',
220
+ ['a',md_url('http://example.com/?foo=1&bar=2'),'b'] ],
221
+ ['<andrea@censi.org>',
222
+ [md_email('andrea@censi.org')], 'Email address'],
223
+ ['<mailto:andrea@censi.org>'],
224
+ ["Developmen <http://rubyforge.org/projects/maruku/>",
225
+ ["Developmen ", md_url("http://rubyforge.org/projects/maruku/")]],
226
+ ["a<!-- -->b", ['a',md_html('<!-- -->'),'b'],
227
+ 'HTML Comment'],
228
+
229
+ ["a<!--", :throw, 'Bad HTML Comment'],
230
+ ["a<!-- ", :throw, 'Bad HTML Comment'],
231
+
232
+ ["<?xml <?!--!`3 ?>", [md_xml_instr('xml','<?!--!`3')], 'XML processing instruction'],
233
+ ["<? <?!--!`3 ?>", [md_xml_instr('','<?!--!`3')] ],
234
+
235
+ ["<? ", :throw, 'Bad Server directive'],
236
+
237
+ ["a <b", :throw, 'Bad HTML 1'],
238
+ ["<b", :throw, 'Bad HTML 2'],
239
+ ["<b!", :throw, 'Bad HTML 3'],
240
+ ['`<div>`, `<table>`, `<pre>`, `<p>`',
241
+ [md_code('<div>'),', ',md_code('<table>'),', ',
242
+ md_code('<pre>'),', ',md_code('<p>')],
243
+ 'Multiple HTLM tags'],
244
+
245
+ ["&andrea", ["&andrea"], 'Parsing of entities'],
246
+ # no escaping is allowed
247
+ # ["\\&andrea;", ["&andrea;"]],
248
+ ["l&andrea;", ["l", md_entity('andrea')] ],
249
+ ["&&andrea;", ["&", md_entity('andrea')] ],
250
+ ["&123;;&amp;",[md_entity('123'),';',md_entity('amp')]],
251
+
252
+ ["a\nThe [syntax page] [s] provides",
253
+ ['a The ', md_link(['syntax page'],'s'), ' provides'], 'Regression'],
254
+
255
+ ['![a](url "ti"tle")', [md_im_image(['a'],'url','ti"tle')],
256
+ "Image with quotes"],
257
+ ['![a](url \'ti"tle\')' ],
258
+
259
+ ['[bar](/url/ "Title with "quotes" inside")',
260
+ [md_im_link(["bar"],'/url/', 'Title with "quotes" inside')],
261
+ "Link with quotes"],
262
+
263
+ # We dropped this idea
264
+ # ['$20,000 and $30,000', ['$20,000 and $30,000'], 'Math: spaces'],
265
+ ['$20,000$', [md_inline_math('20,000')]],
266
+ # ['$ 20,000$', ['$ 20,000$']],
267
+ # ['$20,000 $ $20,000$', ['$20,000 $ ', md_inline_math('20,000')]],
268
+ ["#{Maruku8}", [Maruku8], "Reading UTF-8"],
269
+ # ["#{AccIta1}", [AccIta8], "Converting ISO-8859-1 to UTF-8",
270
+ # {:encoding => 'iso-8859-1'}],
271
+
272
+ ]
273
+
274
+ good_cases = unit_tests_for_attribute_lists + good_cases
275
+
276
+ count = 1; last_comment=""; last_expected=:throw
277
+ good_cases.each do |t|
278
+ if not t[1]
279
+ t[1] = last_expected
280
+ else
281
+ last_expected = t[1]
282
+ end
283
+ if not t[2]
284
+ t[2] = last_comment + " #{count+=1}"
285
+ else
286
+ last_comment = t[2]; count=1
287
+ end
288
+ end
289
+
290
+
291
+
292
+ @verbose = verbose
293
+ m = Maruku.new
294
+ m.attributes[:on_error] = :raise
295
+ Globals[:debug_keep_ials] = true
296
+
297
+ num_ok = 0
298
+ good_cases.each do |input, expected, comment|
299
+ output = nil
300
+ begin
301
+ output = m.parse_span_better(input)
302
+ #lines = Maruku.split_lines input
303
+ #output = m.parse_lines_as_span(lines)
304
+ rescue Exception => e
305
+ if not expected == :throw
306
+ ex = e.inspect+ "\n"+ e.backtrace.join("\n")
307
+ s = comment+describe_difference(input, expected, output)
308
+
309
+ print_status(comment,'CRASHED :-(', ex+s)
310
+ raise e if @break_on_first_error
311
+ else
312
+ quiet || print_status(comment,'OK')
313
+ num_ok += 1
314
+ end
315
+ end
316
+
317
+ if not expected == :throw
318
+ if not (expected == output)
319
+ s = comment+describe_difference(input, expected, output)
320
+ print_status(comment, 'FAILED', s)
321
+ break if break_on_first_error
322
+ else
323
+ num_ok += 1
324
+ quiet || print_status(comment, 'OK')
325
+ end
326
+ else # I expected a raise
327
+ if output
328
+ s = comment+describe_difference(input, expected, output)
329
+
330
+ print_status(comment, 'FAILED (no throw)', s)
331
+ break if break_on_first_error
332
+ end
333
+ end
334
+ end # do
335
+ if num_ok != good_cases.size
336
+ return false
337
+ else
338
+ return true
339
+ end
340
+ end
341
+
342
+ PAD=40
343
+ def print_status(comment, status, verbose_text=nil)
344
+ if comment.size < PAD
345
+ comment = comment + (" "*(PAD-comment.size))
346
+ end
347
+ puts "- #{comment} #{status}"
348
+ if @verbose and verbose_text
349
+ puts verbose_text
350
+ end
351
+ end
352
+
353
+
354
+ def describe_difference(input, expected, output)
355
+ "\nInput:\n #{input.inspect}" +
356
+ "\nExpected:\n #{expected.inspect}" +
357
+ "\nOutput:\n #{output.inspect}\n"
358
+ end
359
+ end end
360
+
361
+ class Maruku
362
+ include MaRuKu::Tests
363
+ end
364
+
365
+ verbose = ARGV.include? 'v'
366
+ break_on_first = ARGV.include? 'b'
367
+ quiet = ARGV.include? 'q'
368
+ ok = Maruku.new.test_span_parser(verbose, break_on_first, quiet)
369
+
370
+ exit (ok ? 0 : 1)