maruku 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/bin/{maruku0.3 → marudown} +6 -14
  2. data/bin/maruku +1 -1
  3. data/bin/marutest +37 -9
  4. data/docs/TOFIX.html +22 -0
  5. data/docs/TOFIX.md +3 -0
  6. data/docs/changelog-0.2.13.html +30 -0
  7. data/docs/changelog-0.2.13.md +6 -0
  8. data/docs/changelog-0.3.html +19 -5
  9. data/docs/faq.html +51 -40
  10. data/docs/faq.md +3 -3
  11. data/docs/hidden_o_n_squared.md +10 -0
  12. data/docs/index.html +84 -396
  13. data/docs/markdown_syntax.html +139 -330
  14. data/docs/markdown_syntax.md +80 -93
  15. data/docs/maruku.html +84 -396
  16. data/docs/maruku.md +88 -158
  17. data/docs/proposal.html +13 -106
  18. data/docs/proposal.md +3 -3
  19. data/docs/todo.html +38 -28
  20. data/lib/maruku.rb +77 -11
  21. data/lib/maruku/attributes.rb +186 -0
  22. data/lib/maruku/defaults.rb +40 -0
  23. data/lib/maruku/errors_management.rb +55 -39
  24. data/lib/maruku/helpers.rb +156 -72
  25. data/lib/maruku/input/charsource.rb +319 -0
  26. data/lib/maruku/{html_helper.rb → input/html_helper.rb} +30 -9
  27. data/lib/maruku/input/linesource.rb +111 -0
  28. data/lib/maruku/input/parse_block.rb +562 -0
  29. data/lib/maruku/{parse_doc.rb → input/parse_doc.rb} +60 -28
  30. data/lib/maruku/{parse_span_better.rb → input/parse_span_better.rb} +226 -256
  31. data/lib/maruku/input/type_detection.rb +137 -0
  32. data/lib/maruku/maruku.rb +33 -0
  33. data/lib/maruku/{to_html.rb → output/to_html.rb} +151 -132
  34. data/lib/maruku/{to_latex.rb → output/to_latex.rb} +31 -35
  35. data/lib/maruku/{to_latex_entities.rb → output/to_latex_entities.rb} +25 -3
  36. data/lib/maruku/output/to_latex_strings.rb +64 -0
  37. data/lib/maruku/output/to_markdown.rb +164 -0
  38. data/lib/maruku/{to_s.rb → output/to_s.rb} +6 -0
  39. data/lib/maruku/string_utils.rb +12 -181
  40. data/lib/maruku/structures.rb +91 -67
  41. data/lib/maruku/structures_inspect.rb +78 -0
  42. data/lib/maruku/structures_iterators.rb +24 -2
  43. data/lib/maruku/tests/benchmark.rb +41 -9
  44. data/lib/maruku/tests/new_parser.rb +317 -286
  45. data/lib/maruku/tests/tests.rb +20 -0
  46. data/lib/maruku/toc.rb +64 -64
  47. data/lib/maruku/usage/example1.rb +33 -0
  48. data/lib/maruku/version.rb +8 -2
  49. data/tests/unittest/abbreviations.md +27 -16
  50. data/tests/unittest/attributes/attributes.md +89 -0
  51. data/tests/unittest/attributes/circular.md +51 -0
  52. data/tests/unittest/attributes/default.md +47 -0
  53. data/tests/unittest/blank.md +10 -6
  54. data/tests/unittest/blanks_in_code.md +26 -26
  55. data/tests/unittest/code.md +9 -9
  56. data/tests/unittest/code2.md +12 -13
  57. data/tests/unittest/code3.md +34 -34
  58. data/tests/unittest/easy.md +9 -7
  59. data/tests/unittest/email.md +9 -7
  60. data/tests/unittest/encoding/iso-8859-1.md +41 -4
  61. data/tests/unittest/encoding/utf-8.md +6 -5
  62. data/tests/unittest/entities.md +52 -80
  63. data/tests/unittest/escaping.md +47 -35
  64. data/tests/unittest/extra_dl.md +19 -29
  65. data/tests/unittest/extra_header_id.md +31 -24
  66. data/tests/unittest/extra_table1.md +14 -32
  67. data/tests/unittest/footnotes.md +58 -42
  68. data/tests/unittest/headers.md +11 -11
  69. data/tests/unittest/hrule.md +14 -24
  70. data/tests/unittest/images.md +41 -26
  71. data/tests/unittest/inline_html.md +104 -56
  72. data/tests/unittest/inline_html2.md +38 -0
  73. data/tests/unittest/links.md +74 -33
  74. data/tests/unittest/list1.md +18 -15
  75. data/tests/unittest/list2.md +31 -13
  76. data/tests/unittest/list3.md +29 -28
  77. data/tests/unittest/list4.md +103 -12
  78. data/tests/unittest/lists.md +86 -53
  79. data/tests/unittest/lists6.md +53 -0
  80. data/tests/unittest/lists7.md +31 -0
  81. data/tests/unittest/lists_after_paragraph.md +105 -71
  82. data/tests/unittest/lists_ol.md +149 -73
  83. data/tests/unittest/misc_sw.md +366 -326
  84. data/tests/unittest/notyet/escape.md +10 -10
  85. data/tests/unittest/notyet/header_after_par.md +20 -14
  86. data/tests/unittest/notyet/ticks.md +8 -35
  87. data/tests/unittest/notyet/triggering.md +72 -45
  88. data/tests/unittest/olist.md +78 -0
  89. data/tests/unittest/one.md +5 -3
  90. data/tests/unittest/paragraph.md +5 -3
  91. data/tests/unittest/paragraph_rules/dont_merge_ref.md +15 -9
  92. data/tests/unittest/paragraph_rules/tab_is_blank.md +9 -5
  93. data/tests/unittest/paragraphs.md +21 -26
  94. data/tests/unittest/recover/recover_links.md +6 -5
  95. data/tests/unittest/references/long_example.md +39 -30
  96. data/tests/unittest/references/spaces_and_numbers.md +2 -2
  97. data/tests/unittest/syntax_hl.md +33 -31
  98. data/tests/unittest/test.md +4 -6
  99. data/tests/unittest/wrapping.md +43 -26
  100. metadata +160 -139
  101. data/docs/markdown_extra2.html +0 -87
  102. data/docs/markdown_extra2.md +0 -83
  103. data/docs/markdown_syntax_2.html +0 -152
  104. data/lib/maruku/parse_block.rb +0 -564
  105. data/lib/maruku/parse_span.rb +0 -451
  106. data/lib/maruku/to_latex_strings.rb +0 -59
  107. data/lib/maruku/to_markdown.rb +0 -110
  108. data/lib/test.rb +0 -29
@@ -1,10 +1,31 @@
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
+ #++
1
20
 
2
21
 
22
+ module MaRuKu
3
23
 
4
24
  class MDElement
5
25
 
6
- # yields to each element of specified node_type
7
- def each_element(e_node_type, &block)
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)
8
29
  @children.each do |c|
9
30
  if c.kind_of? MDElement
10
31
  if (not e_node_type) || (e_node_type == c.node_type)
@@ -37,3 +58,4 @@ class MDElement
37
58
  end
38
59
 
39
60
  end
61
+ end
@@ -1,3 +1,24 @@
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
+
1
22
  require 'maruku'
2
23
  require 'bluecloth'
3
24
 
@@ -6,15 +27,18 @@ data = $stdin.read
6
27
 
7
28
  num = 10
8
29
 
30
+ if ARGV.size > 0 && ((n=ARGV[0].to_i) != 0)
31
+ num = n
32
+ end
33
+
9
34
  methods =
10
35
  [
11
36
 
37
+ [Maruku, :to_html],
12
38
  [BlueCloth, :to_html],
13
- [Maruku, :class],
14
- # [Maruku, :to_html],
15
- # [Maruku, :to_latex]
39
+ [Maruku, :to_latex]
16
40
 
17
- ]*2
41
+ ]
18
42
 
19
43
  #methods = [[Maruku, :class]]
20
44
  #num = 10
@@ -26,7 +50,7 @@ methods .map do |c, method|
26
50
  start = Time.now
27
51
  doc = nil
28
52
  for i in 1..num
29
- puts "#{i}"
53
+ $stdout.write "#{i} "; $stdout.flush
30
54
  doc = c.new(data)
31
55
  end
32
56
  stop = Time.now
@@ -34,17 +58,25 @@ methods .map do |c, method|
34
58
 
35
59
  start = Time.now
36
60
  for i in 1..num
37
- puts "#{i}"
61
+ $stdout.write "#{i} "; $stdout.flush
38
62
  s = doc.send method
39
63
  end
40
64
  stop = Time.now
41
65
  rendering = (stop-start)/num
42
66
 
67
+ puts ("%s (%s): parsing %0.2f sec + rendering %0.2f sec "+
68
+ "= %0.2f sec ") % [c, method, parsing,rendering,parsing+rendering]
69
+
43
70
  [c, method, parsing, rendering]
44
71
  end
45
72
 
46
- for c, method, parsing, rendering in stats
47
- puts ("%s (%s): parsing %0.2f sec + rendering %0.2f sec "+
48
- "= %0.2f sec ") % [c, method, parsing,rendering,parsing+rendering]
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]
49
81
  end
50
82
 
@@ -1,318 +1,349 @@
1
- require 'maruku'
2
- require 'maruku/helpers'
3
-
4
- require 'maruku/parse_span_better'
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
+ #++
5
20
 
6
- class Maruku
7
21
 
22
+ require 'maruku'
8
23
 
9
- class TestNewParser
10
- include Helpers
11
- include MarukuErrors
12
-
13
- # 5 accented letters in italian, encoded as UTF-8
14
- AccIta8 = "\303\240\303\250\303\254\303\262\303\271"
24
+ module MaRuKu; module Tests
25
+ # 5 accented letters in italian, encoded as UTF-8
26
+ AccIta8 = "\303\240\303\250\303\254\303\262\303\271"
15
27
 
16
- # Same letters, written in ISO-8859-1 (one byte per letter)
17
- AccIta1 = "\340\350\354\362\371"
28
+ # Same letters, written in ISO-8859-1 (one byte per letter)
29
+ AccIta1 = "\340\350\354\362\371"
30
+
31
+ # The word MA-RU-KU, written in katakana using UTF-8
32
+ Maruku8 = "\343\203\236\343\203\253\343\202\257"
33
+
34
+ def test_span_parser(verbose, break_on_first_error, quiet)
35
+ good_cases = [
18
36
 
19
- # The word MA-RU-KU, written in katakana using UTF-8
20
- Maruku8 = "\343\203\236\343\203\253\343\202\257"
37
+ ["", [], 'Empty string gives empty list'],
38
+ ["a", ["a"], 'Easy char'],
39
+ [" a", ["a"], 'First space in the paragraph is ignored'],
40
+ ["a\n \n", ["a"], 'Last spaces in the paragraphs are ignored'],
41
+ [' ', [], 'One char => nothing'],
42
+ [' ', [], 'Two chars => nothing'],
43
+ ['a b', ['a b'], 'Spaces are compressed'],
44
+ ['a b', ['a b'], 'Newlines are spaces'],
45
+ ["a\nb", ['a b'], 'Newlines are spaces'],
46
+ ["a\n b", ['a b'], 'Compress newlines 1'],
47
+ ["a \nb", ['a b'], 'Compress newlines 2'],
48
+ [" \nb", ['b'], 'Compress newlines 3'],
49
+ ["\nb", ['b'], 'Compress newlines 4'],
50
+ ["b\n", ['b'], 'Compress newlines 5'],
51
+ ["\n", [], 'Compress newlines 6'],
52
+ ["\n\n\n", [], 'Compress newlines 7'],
21
53
 
22
- def do_it(verbose, break_on_first_error)
23
- good_cases = [
24
- ["", [], 'Empty string gives empty list'],
25
- ["a", ["a"], 'Easy char'],
26
- [' ', [' '], 'One char => one string'],
27
- [' ', [' '], 'Two chars => one char'],
28
- ['a b', ['a b'], 'Spaces are compressed'],
29
- ['a b', ['a b'], 'Newlines are spaces'],
30
- ["a\nb", ['a b'], 'Newlines are spaces'],
31
- ["a\n b", ['a b'], 'Compress newlines 1'],
32
- ["a \nb", ['a b'], 'Compress newlines 2'],
33
- [" \nb", [' b'], 'Compress newlines 3'],
34
- ["\nb", [' b'], 'Compress newlines 4'],
35
- ["b\n", ['b '], 'Compress newlines 5'],
36
- ["\n", [' '], 'Compress newlines 6'],
37
- ["\n\n\n", [' '], 'Compress newlines 7'],
38
-
39
- [nil, :throw, "Should throw on nil input"],
40
-
41
- # Code blocks
42
- ["`" , :throw, 'Unclosed single ticks'],
43
- ["``" , :throw, 'Unclosed double ticks'],
44
- ["`a`" , [md_code('a')], 'Simple inline code'],
45
- ["`` ` ``" , [md_code('`')], ],
46
- ["`` \\` ``" , [md_code('\\`')], ],
47
- ["``a``" , [md_code('a')], ],
48
- ["`` a ``" , [md_code('a')], ],
49
-
50
- # Newlines
51
- ["a \n", ['a',md_el(:linebreak)], 'Two spaces give br.'],
52
- ["a \n", ['a '], 'Newlines 2'],
53
- [" \n", [md_el(:linebreak)], 'Newlines 3'],
54
- [" \n \n", [md_el(:linebreak),md_el(:linebreak)],'Newlines 3'],
55
- [" \na \n", [md_el(:linebreak),'a',md_el(:linebreak)],'Newlines 3'],
56
-
57
- # Inline HTML
58
- ["a < b", ['a < b'], '< can be on itself'],
59
- ["<hr>", [md_html('<hr />')], 'HR will be sanitized'],
60
- ["<hr/>", [md_html('<hr />')], 'Closed tag is ok'],
61
- ["<hr />", [md_html('<hr />')], 'Closed tag is ok 2'],
62
- ["<hr/>a", [md_html('<hr />'),'a'], 'Closed tag is ok 2'],
63
- ["<em></em>a", [md_html('<em></em>'),'a'], 'Inline HTML 1'],
64
- ["<em>e</em>a", [md_html('<em>e</em>'),'a'], 'Inline HTML 2'],
65
- ["a<em>e</em>b", ['a',md_html('<em>e</em>'),'b'], 'Inline HTML 3'],
66
- ["<em>e</em>a<em>f</em>",
67
- [md_html('<em>e</em>'),'a',md_html('<em>f</em>')],
68
- 'Inline HTML 4'],
69
- ["<em>e</em><em>f</em>a",
70
- [md_html('<em>e</em>'),md_html('<em>f</em>'),'a'],
71
- 'Inline HTML 5'],
72
-
73
- ["<img src='a' />", [md_html("<img src='a' />")], 'Attributes'],
74
- ["<img src='a'/>"],
75
-
76
- # emphasis
77
- ["**", :throw, 'Unclosed double **'],
78
- ["\\*", ['*'], 'Escaping of *'],
79
- ["a *b* ", ['a ', md_em('b'),' '], 'Emphasis 1'],
80
- ["a *b*", ['a ', md_em('b')], 'Emphasis 2'],
81
- ["a * b", ['a * b'], 'Emphasis 3'],
82
- ["a * b*", :throw, 'Unclosed emphasis'],
83
- # same with underscore
84
- ["__", :throw, 'Unclosed double __'],
85
- ["\\_", ['_'], 'Escaping of _'],
86
- ["a _b_ ", ['a ', md_em('b'),' '], 'Emphasis 4'],
87
- ["a _b_", ['a ', md_em('b')], 'Emphasis 5'],
88
- ["a _ b", ['a _ b'], 'Emphasis 6'],
89
- ["a _ b_", :throw, 'Unclosed emphasis'],
90
- ["_b_", [md_em('b')], 'Emphasis 7'],
91
- ["_b_ _c_", [md_em('b'),' ',md_em('c')], 'Emphasis 8'],
92
- ["_b__c_", [md_em('b'),md_em('c')], 'Emphasis 9'],
93
- # strong
94
- ["**a*", :throw, 'Unclosed double ** 2'],
95
- ["\\**a*", ['*', md_em('a')], 'Escaping of *'],
96
- ["a **b** ", ['a ', md_strong('b'),' '], 'Emphasis 1'],
97
- ["a **b**", ['a ', md_strong('b')], 'Emphasis 2'],
98
- ["a ** b", ['a ** b'], 'Emphasis 3'],
99
- ["a ** b**", :throw, 'Unclosed emphasis'],
100
- ["**b****c**", [md_strong('b'),md_strong('c')], 'Emphasis 9'],
101
- # strong (with underscore)
102
- ["__a_", :throw, 'Unclosed double __ 2'],
103
- ["\\__a_", ['_', md_em('a')], 'Escaping of _'],
104
- ["a __b__ ", ['a ', md_strong('b'),' '], 'Emphasis 1'],
105
- ["a __b__", ['a ', md_strong('b')], 'Emphasis 2'],
106
- ["a __ b", ['a __ b'], 'Emphasis 3'],
107
- ["a __ b__", :throw, 'Unclosed emphasis'],
108
- ["__b____c__", [md_strong('b'),md_strong('c')], 'Emphasis 9'],
109
- # extra strong
110
- ["***a**", :throw, 'Unclosed triple *** '],
111
- ["\\***a**", ['*', md_strong('a')], 'Escaping of *'],
112
- ["a ***b*** ", ['a ', md_emstrong('b'),' '], 'Strong elements'],
113
- ["a ***b***", ['a ', md_emstrong('b')]],
114
- ["a *** b", ['a *** b']],
115
- ["a ** * b", ['a ** * b']],
116
- ["***b******c***", [md_emstrong('b'),md_emstrong('c')]],
117
- ["a *** b***", :throw, 'Unclosed emphasis'],
118
- # same with underscores
119
- ["___a__", :throw, 'Unclosed triple *** '],
120
- ["\\___a__", ['_', md_strong('a')], 'Escaping of *'],
121
- ["a ___b___ ", ['a ', md_emstrong('b'),' '], 'Strong elements'],
122
- ["a ___b___", ['a ', md_emstrong('b')]],
123
- ["a ___ b", ['a ___ b']],
124
- ["a __ _ b", ['a __ _ b']],
125
- ["___b______c___", [md_emstrong('b'),md_emstrong('c')]],
126
- ["a ___ b___", :throw, 'Unclosed emphasis'],
127
- # mixing is bad
128
- ["*a_", :throw, 'Mixing is bad'],
129
- ["_a*", :throw],
130
- ["**a__", :throw],
131
- ["__a**", :throw],
132
- ["___a***", :throw],
133
- ["***a___", :throw],
134
- # links of the form [text][ref]
135
- ["\\[a]", ["[a]"], 'Escaping 1'],
136
- ["\\[a\\]", ["[a]"], 'Escaping 2'],
137
- ["[a]", ["a"], 'Not a link'],
138
- ["[a][]", [ md_link(["a"],'')], 'Empty link'],
139
- ["[a][]b", [ md_link(["a"],''),'b'], 'Empty link'],
140
- ["[a\\]][]", [ md_link(["a]"],'')], 'Escape inside link'],
141
-
142
- ["[a", :throw, 'Link not closed'],
143
- ["[a][", :throw, 'Ref not closed'],
144
-
145
- # links of the form [text](url)
146
- ["\\[a](b)", ["[a](b)"], 'Links'],
147
- ["[a](url)c", [md_im_link(['a'],'url'),'c'], 'url'],
148
- ["[a]( url )c" ],
149
- ["[a] ( url )c" ],
150
- ["[a] ( url)c" ],
54
+ [nil, :throw, "Should throw on nil input"],
55
+
56
+ # Code blocks
57
+ ["`" , :throw, 'Unclosed single ticks'],
58
+ ["``" , :throw, 'Unclosed double ticks'],
59
+ ["`a`" , [md_code('a')], 'Simple inline code'],
60
+ ["`` ` ``" , [md_code('`')], ],
61
+ ["`` \\` ``" , [md_code('\\`')], ],
62
+ ["``a``" , [md_code('a')], ],
63
+ ["`` a ``" , [md_code('a')], ],
64
+
65
+ # Newlines
66
+ ["a \n", ['a',md_el(:linebreak)], 'Two spaces give br.'],
67
+ ["a \n", ['a'], 'Newlines 2'],
68
+ [" \n", [md_el(:linebreak)], 'Newlines 3'],
69
+ [" \n \n", [md_el(:linebreak),md_el(:linebreak)],'Newlines 3'],
70
+ [" \na \n", [md_el(:linebreak),'a',md_el(:linebreak)],'Newlines 3'],
71
+
72
+ # Inline HTML
73
+ ["a < b", ['a < b'], '< can be on itself'],
74
+ ["<hr>", [md_html('<hr />')], 'HR will be sanitized'],
75
+ ["<hr/>", [md_html('<hr />')], 'Closed tag is ok'],
76
+ ["<hr />", [md_html('<hr />')], 'Closed tag is ok 2'],
77
+ ["<hr/>a", [md_html('<hr />'),'a'], 'Closed tag is ok 2'],
78
+ ["<em></em>a", [md_html('<em></em>'),'a'], 'Inline HTML 1'],
79
+ ["<em>e</em>a", [md_html('<em>e</em>'),'a'], 'Inline HTML 2'],
80
+ ["a<em>e</em>b", ['a',md_html('<em>e</em>'),'b'], 'Inline HTML 3'],
81
+ ["<em>e</em>a<em>f</em>",
82
+ [md_html('<em>e</em>'),'a',md_html('<em>f</em>')],
83
+ 'Inline HTML 4'],
84
+ ["<em>e</em><em>f</em>a",
85
+ [md_html('<em>e</em>'),md_html('<em>f</em>'),'a'],
86
+ 'Inline HTML 5'],
151
87
 
152
- ["[a](ur:/l/ 'Title')", [md_im_link(['a'],'ur:/l/','Title')],
153
- 'url and title'],
154
- ["[a] ( ur:/l/ \"Title\")" ],
155
- ["[a] ( ur:/l/ \"Title\")" ],
156
- ["[a]( ur:/l/ Title)", :throw, "Must quote title" ],
88
+ ["<img src='a' />", [md_html("<img src='a' />")], 'Attributes'],
89
+ ["<img src='a'/>"],
90
+
91
+ # emphasis
92
+ ["**", :throw, 'Unclosed double **'],
93
+ ["\\*", ['*'], 'Escaping of *'],
94
+ ["a *b* ", ['a ', md_em('b')], 'Emphasis 1'],
95
+ ["a *b*", ['a ', md_em('b')], 'Emphasis 2'],
96
+ ["a * b", ['a * b'], 'Emphasis 3'],
97
+ ["a * b*", :throw, 'Unclosed emphasis'],
98
+ # same with underscore
99
+ ["__", :throw, 'Unclosed double __'],
100
+ ["\\_", ['_'], 'Escaping of _'],
101
+ ["a _b_ ", ['a ', md_em('b')], 'Emphasis 4'],
102
+ ["a _b_", ['a ', md_em('b')], 'Emphasis 5'],
103
+ ["a _ b", ['a _ b'], 'Emphasis 6'],
104
+ ["a _ b_", :throw, 'Unclosed emphasis'],
105
+ ["_b_", [md_em('b')], 'Emphasis 7'],
106
+ ["_b_ _c_", [md_em('b'),' ',md_em('c')], 'Emphasis 8'],
107
+ ["_b__c_", [md_em('b'),md_em('c')], 'Emphasis 9'],
108
+ # strong
109
+ ["**a*", :throw, 'Unclosed double ** 2'],
110
+ ["\\**a*", ['*', md_em('a')], 'Escaping of *'],
111
+ ["a **b** ", ['a ', md_strong('b')], 'Emphasis 1'],
112
+ ["a **b**", ['a ', md_strong('b')], 'Emphasis 2'],
113
+ ["a ** b", ['a ** b'], 'Emphasis 3'],
114
+ ["a ** b**", :throw, 'Unclosed emphasis'],
115
+ ["**b****c**", [md_strong('b'),md_strong('c')], 'Emphasis 9'],
116
+ # strong (with underscore)
117
+ ["__a_", :throw, 'Unclosed double __ 2'],
118
+ ["\\__a_", ['_', md_em('a')], 'Escaping of _'],
119
+ ["a __b__ ", ['a ', md_strong('b')], 'Emphasis 1'],
120
+ ["a __b__", ['a ', md_strong('b')], 'Emphasis 2'],
121
+ ["a __ b", ['a __ b'], 'Emphasis 3'],
122
+ ["a __ b__", :throw, 'Unclosed emphasis'],
123
+ ["__b____c__", [md_strong('b'),md_strong('c')], 'Emphasis 9'],
124
+ # extra strong
125
+ ["***a**", :throw, 'Unclosed triple *** '],
126
+ ["\\***a**", ['*', md_strong('a')], 'Escaping of *'],
127
+ ["a ***b*** ", ['a ', md_emstrong('b')], 'Strong elements'],
128
+ ["a ***b***", ['a ', md_emstrong('b')]],
129
+ ["a *** b", ['a *** b']],
130
+ ["a ** * b", ['a ** * b']],
131
+ ["***b******c***", [md_emstrong('b'),md_emstrong('c')]],
132
+ ["a *** b***", :throw, 'Unclosed emphasis'],
133
+ # same with underscores
134
+ ["___a__", :throw, 'Unclosed triple *** '],
135
+ ["\\___a__", ['_', md_strong('a')], 'Escaping of *'],
136
+ ["a ___b___ ", ['a ', md_emstrong('b')], 'Strong elements'],
137
+ ["a ___b___", ['a ', md_emstrong('b')]],
138
+ ["a ___ b", ['a ___ b']],
139
+ ["a __ _ b", ['a __ _ b']],
140
+ ["___b______c___", [md_emstrong('b'),md_emstrong('c')]],
141
+ ["a ___ b___", :throw, 'Unclosed emphasis'],
142
+ # mixing is bad
143
+ ["*a_", :throw, 'Mixing is bad'],
144
+ ["_a*", :throw],
145
+ ["**a__", :throw],
146
+ ["__a**", :throw],
147
+ ["___a***", :throw],
148
+ ["***a___", :throw],
149
+ # links of the form [text][ref]
150
+ ["\\[a]", ["[a]"], 'Escaping 1'],
151
+ ["\\[a\\]", ["[a]"], 'Escaping 2'],
152
+ ["[a]", ["a"], 'Not a link'],
153
+ ["[a][]", [ md_link(["a"],'')], 'Empty link'],
154
+ ["[a][]b", [ md_link(["a"],''),'b'], 'Empty link'],
155
+ ["[a\\]][]", [ md_link(["a]"],'')], 'Escape inside link'],
156
+
157
+ ["[a", :throw, 'Link not closed'],
158
+ ["[a][", :throw, 'Ref not closed'],
159
+
160
+ # links of the form [text](url)
161
+ ["\\[a](b)", ["[a](b)"], 'Links'],
162
+ ["[a](url)c", [md_im_link(['a'],'url'),'c'], 'url'],
163
+ ["[a]( url )c" ],
164
+ ["[a] ( url )c" ],
165
+ ["[a] ( url)c" ],
166
+
167
+ ["[a](ur:/l/ 'Title')", [md_im_link(['a'],'ur:/l/','Title')],
168
+ 'url and title'],
169
+ ["[a] ( ur:/l/ \"Title\")" ],
170
+ ["[a] ( ur:/l/ \"Title\")" ],
171
+ ["[a]( ur:/l/ Title)", :throw, "Must quote title" ],
157
172
 
158
- ["[a](url 'Tit\\\"l\\\\e')", [md_im_link(['a'],'url','Tit"l\\e')],
159
- 'url and title escaped'],
160
- ["[a] ( url \"Tit\\\"l\\\\e\")" ],
161
- ["[a] ( url \"Tit\\\"l\\\\e\" )" ],
162
- ['[a] ( url "Tit\\"l\\\\e" )' ],
163
- ["[a]()", [md_im_link(['a'],'')], 'No URL is OK'],
173
+ ["[a](url 'Tit\\\"l\\\\e')", [md_im_link(['a'],'url','Tit"l\\e')],
174
+ 'url and title escaped'],
175
+ ["[a] ( url \"Tit\\\"l\\\\e\")" ],
176
+ ["[a] ( url \"Tit\\\"l\\\\e\" )" ],
177
+ ['[a] ( url "Tit\\"l\\\\e" )' ],
178
+ ["[a]()", [md_im_link(['a'],'')], 'No URL is OK'],
179
+
180
+ ["[a](\"Title\")", :throw, "No url specified" ],
181
+ ["[a](url \"Title)", :throw, "Unclosed quotes" ],
182
+ ["[a](url \"Title\\\")", :throw],
183
+ ["[a](url \"Title\" ", :throw],
184
+
185
+ ["[a](url \'Title\")", :throw, "Mixing is bad" ],
186
+ ["[a](url \"Title\')"],
187
+
188
+ ["[a](/url)", [md_im_link(['a'],'/url')], 'Funny chars in url'],
189
+ ["[a](#url)", [md_im_link(['a'],'#url')]],
190
+ ["[a](</script?foo=1&bar=2>)", [md_im_link(['a'],'/script?foo=1&bar=2')]],
191
+
192
+
193
+ # Images
194
+ ["\\![a](url)", ['!', md_im_link(['a'],'url') ], 'Escaping images'],
164
195
 
165
- ["[a](\"Title\")", :throw, "No url specified" ],
166
- ["[a](url \"Title)", :throw, "Unclosed quotes" ],
167
- ["[a](url \"Title\\\")", :throw],
168
- ["[a](url \"Title\" ", :throw],
196
+ ["![a](url)", [md_im_image(['a'],'url')], 'Image no title'],
197
+ ["![a]( url )" ],
198
+ ["![a] ( url )" ],
199
+ ["![a] ( url)" ],
169
200
 
170
- ["[a](url \'Title\")", :throw, "Mixing is bad" ],
171
- ["[a](url \"Title\')"],
172
-
173
- ["[a](/url)", [md_im_link(['a'],'/url')], 'Funny chars in url'],
174
- ["[a](#url)", [md_im_link(['a'],'#url')]],
175
- ["[a](</script?foo=1&bar=2>)", [md_im_link(['a'],'/script?foo=1&bar=2')]],
176
-
177
-
178
- # Images
179
- ["\\![a](url)", ['!', md_im_link(['a'],'url') ], 'Escaping images'],
180
-
181
- ["![a](url)", [md_im_image(['a'],'url')], 'Image no title'],
182
- ["![a]( url )" ],
183
- ["![a] ( url )" ],
184
- ["![a] ( url)" ],
201
+ ["![a](url 'ti\"tle')", [md_im_image(['a'],'url','ti"tle')], 'Image with title'],
202
+ ['![a]( url "ti\\"tle")' ],
185
203
 
186
- ["![a](url 'ti\"tle')", [md_im_image(['a'],'url','ti"tle')], 'Image with title'],
187
- ['![a]( url "ti\\"tle")' ],
204
+ ["![a](url", :throw, 'Invalid images'],
205
+ ["![a( url )" ],
206
+ ["![a] ('url )" ],
188
207
 
189
- ["![a](url", :throw, 'Invalid images'],
190
- ["![a( url )" ],
191
- ["![a] ('url )" ],
208
+ ["![a][imref]", [md_image(['a'],'imref')], 'Image with ref'],
209
+ ["![a][ imref]"],
210
+ ["![a][ imref ]"],
211
+ ["![a][\timref\t]"],
212
+
213
+ ['<http://example.com/?foo=1&bar=2>',
214
+ [md_url('http://example.com/?foo=1&bar=2')], 'Immediate link'],
215
+ ['a<http://example.com/?foo=1&bar=2>b',
216
+ ['a',md_url('http://example.com/?foo=1&bar=2'),'b'] ],
217
+ ['<andrea@censi.org>',
218
+ [md_email('andrea@censi.org')], 'Email address'],
219
+ ['<mailto:andrea@censi.org>'],
220
+
221
+ ["a<!-- -->b", ['a',md_html('<!-- -->'),'b'],
222
+ 'HTML Comment'],
192
223
 
193
- ["![a][imref]", [md_image(['a'],'imref')], 'Image with ref'],
194
- ["![a][ imref]"],
195
- ["![a][ imref ]"],
196
- ["![a][\timref\t]"],
197
-
198
- ['<http://example.com/?foo=1&bar=2>',
199
- [md_url('http://example.com/?foo=1&bar=2')], 'Immediate link'],
200
- ['a<http://example.com/?foo=1&bar=2>b',
201
- ['a',md_url('http://example.com/?foo=1&bar=2'),'b'] ],
202
- ['<andrea@censi.org>',
203
- [md_email('andrea@censi.org')], 'Email address'],
204
- ['<mailto:andrea@censi.org>'],
205
-
206
- ["a<!-- -->b", ['a',md_html('<!-- -->'),'b'],
207
- 'HTML Comment'],
224
+ ["a<!--", :throw, 'Bad HTML Comment'],
225
+ ["a<!-- ", :throw, 'Bad HTML Comment'],
208
226
 
209
- ["a<!--", :throw, 'Bad HTML Comment'],
210
- ["a<!-- ", :throw, 'Bad HTML Comment'],
227
+ ["<? <?!--!`3 ?>", [md_server('<?!--!`3')], 'Server directive'],
211
228
 
212
- ["a <b", :throw, 'Bad HTML 1'],
213
- ["<b", :throw, 'Bad HTML 2'],
214
- ["<b!", :throw, 'Bad HTML 3'],
215
- ['`<div>`, `<table>`, `<pre>`, `<p>`',
216
- [md_code('<div>'),', ',md_code('<table>'),', ',
217
- md_code('<pre>'),', ',md_code('<p>')],
218
- 'Multiple HTLM tags'],
219
-
220
- ["&andrea", ["&andrea"], 'Parsing of entities'],
229
+ ["<? ", :throw, 'Bad Server directive'],
230
+
231
+ ["a <b", :throw, 'Bad HTML 1'],
232
+ ["<b", :throw, 'Bad HTML 2'],
233
+ ["<b!", :throw, 'Bad HTML 3'],
234
+ ['`<div>`, `<table>`, `<pre>`, `<p>`',
235
+ [md_code('<div>'),', ',md_code('<table>'),', ',
236
+ md_code('<pre>'),', ',md_code('<p>')],
237
+ 'Multiple HTLM tags'],
238
+
239
+ ["&andrea", ["&andrea"], 'Parsing of entities'],
221
240
  # no escaping is allowed
222
241
  # ["\\&andrea;", ["&andrea;"]],
223
- ["&&andrea;", ["&", md_entity('andrea')] ],
224
- ["&123;;&amp;",[md_entity('123'),';',md_entity('amp')]],
225
-
226
- ["a\nThe [syntax page] [s] provides",
227
- ['a The ', md_link(['syntax page'],'s'), ' provides'], 'Regression'],
228
-
229
- ["#{Maruku8}", [Maruku8], "Reading UTF-8"],
230
- ["#{AccIta1}", [AccIta8], "Converting ISO-8859-1 to UTF-8",
231
- {:encoding => 'iso-8859-1'}],
232
- ]
242
+ ["l&andrea;", ["l", md_entity('andrea')] ],
243
+ ["&&andrea;", ["&", md_entity('andrea')] ],
244
+ ["&123;;&amp;",[md_entity('123'),';',md_entity('amp')]],
245
+
246
+ ["a\nThe [syntax page] [s] provides",
247
+ ['a The ', md_link(['syntax page'],'s'), ' provides'], 'Regression'],
248
+
249
+ ['![a](url "ti"tle")', [md_im_image(['a'],'url','ti"tle')],
250
+ "Image with quotes"],
251
+ ['![a](url \'ti"tle\')' ],
252
+
253
+ ['[bar](/url/ "Title with "quotes" inside")',
254
+ [md_im_link(["bar"],'/url/', 'Title with "quotes" inside')],
255
+ "Link with quotes"],
256
+
257
+ ["#{Maruku8}", [Maruku8], "Reading UTF-8"],
258
+ ["#{AccIta1}", [AccIta8], "Converting ISO-8859-1 to UTF-8",
259
+ {:encoding => 'iso-8859-1'}],
260
+ ]
233
261
 
234
- count = 1; last_comment=""; last_expected=:throw
235
- good_cases.each do |t|
236
- if not t[1]
237
- t[1] = last_expected
238
- else
239
- last_expected = t[1]
240
- end
241
- if not t[2]
242
- t[2] = last_comment + " #{count+=1}"
243
- else
244
- last_comment = t[2]; count=1
245
- end
262
+ good_cases = unit_tests_for_attribute_lists + good_cases
263
+
264
+ count = 1; last_comment=""; last_expected=:throw
265
+ good_cases.each do |t|
266
+ if not t[1]
267
+ t[1] = last_expected
268
+ else
269
+ last_expected = t[1]
270
+ end
271
+ if not t[2]
272
+ t[2] = last_comment + " #{count+=1}"
273
+ else
274
+ last_comment = t[2]; count=1
246
275
  end
276
+ end
277
+
247
278
 
248
-
249
- @verbose = verbose
250
- m = Maruku.new
251
- m.meta[:on_error] = :raise
252
-
253
- good_cases.each do |input, expected, comment|
254
- output = nil
255
- begin
256
- output = m.parse_span_better(input)
257
- #lines = Maruku.split_lines input
258
- #output = m.parse_lines_as_span(lines)
259
- rescue Exception => e
260
- if not expected == :throw
261
- ex = e.inspect+ "\n"+ e.backtrace.join("\n")
262
- s = comment+describe_difference(input, expected, output)
263
-
264
- print_status(comment,'CRASHED :-(', ex+s)
265
- raise e if @break_on_first_error
266
- else
267
- print_status(comment,'OK')
268
- end
269
- end
270
-
279
+ @verbose = verbose
280
+ m = Maruku.new
281
+ m.attributes[:on_error] = :raise
282
+
283
+ good_cases.each do |input, expected, comment|
284
+ output = nil
285
+ begin
286
+ output = m.parse_span_better(input)
287
+ #lines = Maruku.split_lines input
288
+ #output = m.parse_lines_as_span(lines)
289
+ rescue Exception => e
271
290
  if not expected == :throw
272
- if not (expected == output)
273
- s = comment+describe_difference(input, expected, output)
274
- print_status(comment, 'FAILED', s)
275
- break if break_on_first_error
276
- else
277
- print_status(comment, 'OK')
278
- end
279
- else # I expected a raise
280
- if output
281
- s = comment+describe_difference(input, expected, output)
291
+ ex = e.inspect+ "\n"+ e.backtrace.join("\n")
292
+ s = comment+describe_difference(input, expected, output)
282
293
 
283
- print_status(comment, 'FAILED (no throw)', s)
284
- break if break_on_first_error
285
- end
294
+ print_status(comment,'CRASHED :-(', ex+s)
295
+ raise e if @break_on_first_error
296
+ else
297
+ quiet || print_status(comment,'OK')
286
298
  end
287
-
288
- end
299
+ end
300
+
301
+ if not expected == :throw
302
+ if not (expected == output)
303
+ s = comment+describe_difference(input, expected, output)
304
+ print_status(comment, 'FAILED', s)
305
+ break if break_on_first_error
306
+ else
307
+ quiet || print_status(comment, 'OK')
308
+ end
309
+ else # I expected a raise
310
+ if output
311
+ s = comment+describe_difference(input, expected, output)
312
+
313
+ print_status(comment, 'FAILED (no throw)', s)
314
+ break if break_on_first_error
315
+ end
316
+ end
317
+
289
318
  end
290
-
291
- PAD=40
292
- def print_status(comment, status, verbose_text=nil)
293
- if comment.size < PAD
294
- comment = comment + (" "*(PAD-comment.size))
295
- end
296
- puts "- #{comment} #{status}"
297
- if @verbose and verbose_text
298
- puts verbose_text
299
- end
319
+ end
320
+
321
+ PAD=40
322
+ def print_status(comment, status, verbose_text=nil)
323
+ if comment.size < PAD
324
+ comment = comment + (" "*(PAD-comment.size))
300
325
  end
301
-
302
-
303
- def describe_difference(input, expected, output)
304
- "\nInput:\n #{input.inspect}" +
305
- "\nExpected:\n #{expected.inspect}" +
306
- "\nOutput:\n #{output.inspect}\n"+
307
- "\nExpected(more):\n #{expected.inspect}" +
308
- "\nOutput(more):\n #{output.inspect}"
326
+ puts "- #{comment} #{status}"
327
+ if @verbose and verbose_text
328
+ puts verbose_text
309
329
  end
310
-
311
- end # class Test
330
+ end
331
+
332
+
333
+ def describe_difference(input, expected, output)
334
+ "\nInput:\n #{input.inspect}" +
335
+ "\nExpected:\n #{expected.inspect}" +
336
+ "\nOutput:\n #{output.inspect}\n"
337
+ end
338
+ end end
339
+
340
+ class Maruku
341
+ include MaRuKu::Tests
312
342
  end
313
343
 
314
344
  verbose = ARGV.include? 'v'
315
345
  break_on_first = ARGV.include? 'b'
316
- Maruku::TestNewParser.new.do_it(verbose, break_on_first)
346
+ quiet = ARGV.include? 'q'
347
+ Maruku.new.test_span_parser(verbose, break_on_first, quiet)
317
348
 
318
349