maruku 0.3.0 → 0.4.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.
- data/bin/{maruku0.3 → marudown} +6 -14
- data/bin/maruku +1 -1
- data/bin/marutest +37 -9
- data/docs/TOFIX.html +22 -0
- data/docs/TOFIX.md +3 -0
- data/docs/changelog-0.2.13.html +30 -0
- data/docs/changelog-0.2.13.md +6 -0
- data/docs/changelog-0.3.html +19 -5
- data/docs/faq.html +51 -40
- data/docs/faq.md +3 -3
- data/docs/hidden_o_n_squared.md +10 -0
- data/docs/index.html +84 -396
- data/docs/markdown_syntax.html +139 -330
- data/docs/markdown_syntax.md +80 -93
- data/docs/maruku.html +84 -396
- data/docs/maruku.md +88 -158
- data/docs/proposal.html +13 -106
- data/docs/proposal.md +3 -3
- data/docs/todo.html +38 -28
- data/lib/maruku.rb +77 -11
- data/lib/maruku/attributes.rb +186 -0
- data/lib/maruku/defaults.rb +40 -0
- data/lib/maruku/errors_management.rb +55 -39
- data/lib/maruku/helpers.rb +156 -72
- data/lib/maruku/input/charsource.rb +319 -0
- data/lib/maruku/{html_helper.rb → input/html_helper.rb} +30 -9
- data/lib/maruku/input/linesource.rb +111 -0
- data/lib/maruku/input/parse_block.rb +562 -0
- data/lib/maruku/{parse_doc.rb → input/parse_doc.rb} +60 -28
- data/lib/maruku/{parse_span_better.rb → input/parse_span_better.rb} +226 -256
- data/lib/maruku/input/type_detection.rb +137 -0
- data/lib/maruku/maruku.rb +33 -0
- data/lib/maruku/{to_html.rb → output/to_html.rb} +151 -132
- data/lib/maruku/{to_latex.rb → output/to_latex.rb} +31 -35
- data/lib/maruku/{to_latex_entities.rb → output/to_latex_entities.rb} +25 -3
- data/lib/maruku/output/to_latex_strings.rb +64 -0
- data/lib/maruku/output/to_markdown.rb +164 -0
- data/lib/maruku/{to_s.rb → output/to_s.rb} +6 -0
- data/lib/maruku/string_utils.rb +12 -181
- data/lib/maruku/structures.rb +91 -67
- data/lib/maruku/structures_inspect.rb +78 -0
- data/lib/maruku/structures_iterators.rb +24 -2
- data/lib/maruku/tests/benchmark.rb +41 -9
- data/lib/maruku/tests/new_parser.rb +317 -286
- data/lib/maruku/tests/tests.rb +20 -0
- data/lib/maruku/toc.rb +64 -64
- data/lib/maruku/usage/example1.rb +33 -0
- data/lib/maruku/version.rb +8 -2
- data/tests/unittest/abbreviations.md +27 -16
- data/tests/unittest/attributes/attributes.md +89 -0
- data/tests/unittest/attributes/circular.md +51 -0
- data/tests/unittest/attributes/default.md +47 -0
- data/tests/unittest/blank.md +10 -6
- data/tests/unittest/blanks_in_code.md +26 -26
- data/tests/unittest/code.md +9 -9
- data/tests/unittest/code2.md +12 -13
- data/tests/unittest/code3.md +34 -34
- data/tests/unittest/easy.md +9 -7
- data/tests/unittest/email.md +9 -7
- data/tests/unittest/encoding/iso-8859-1.md +41 -4
- data/tests/unittest/encoding/utf-8.md +6 -5
- data/tests/unittest/entities.md +52 -80
- data/tests/unittest/escaping.md +47 -35
- data/tests/unittest/extra_dl.md +19 -29
- data/tests/unittest/extra_header_id.md +31 -24
- data/tests/unittest/extra_table1.md +14 -32
- data/tests/unittest/footnotes.md +58 -42
- data/tests/unittest/headers.md +11 -11
- data/tests/unittest/hrule.md +14 -24
- data/tests/unittest/images.md +41 -26
- data/tests/unittest/inline_html.md +104 -56
- data/tests/unittest/inline_html2.md +38 -0
- data/tests/unittest/links.md +74 -33
- data/tests/unittest/list1.md +18 -15
- data/tests/unittest/list2.md +31 -13
- data/tests/unittest/list3.md +29 -28
- data/tests/unittest/list4.md +103 -12
- data/tests/unittest/lists.md +86 -53
- data/tests/unittest/lists6.md +53 -0
- data/tests/unittest/lists7.md +31 -0
- data/tests/unittest/lists_after_paragraph.md +105 -71
- data/tests/unittest/lists_ol.md +149 -73
- data/tests/unittest/misc_sw.md +366 -326
- data/tests/unittest/notyet/escape.md +10 -10
- data/tests/unittest/notyet/header_after_par.md +20 -14
- data/tests/unittest/notyet/ticks.md +8 -35
- data/tests/unittest/notyet/triggering.md +72 -45
- data/tests/unittest/olist.md +78 -0
- data/tests/unittest/one.md +5 -3
- data/tests/unittest/paragraph.md +5 -3
- data/tests/unittest/paragraph_rules/dont_merge_ref.md +15 -9
- data/tests/unittest/paragraph_rules/tab_is_blank.md +9 -5
- data/tests/unittest/paragraphs.md +21 -26
- data/tests/unittest/recover/recover_links.md +6 -5
- data/tests/unittest/references/long_example.md +39 -30
- data/tests/unittest/references/spaces_and_numbers.md +2 -2
- data/tests/unittest/syntax_hl.md +33 -31
- data/tests/unittest/test.md +4 -6
- data/tests/unittest/wrapping.md +43 -26
- metadata +160 -139
- data/docs/markdown_extra2.html +0 -87
- data/docs/markdown_extra2.md +0 -83
- data/docs/markdown_syntax_2.html +0 -152
- data/lib/maruku/parse_block.rb +0 -564
- data/lib/maruku/parse_span.rb +0 -451
- data/lib/maruku/to_latex_strings.rb +0 -59
- data/lib/maruku/to_markdown.rb +0 -110
- 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
|
-
#
|
7
|
-
|
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, :
|
14
|
-
# [Maruku, :to_html],
|
15
|
-
# [Maruku, :to_latex]
|
39
|
+
[Maruku, :to_latex]
|
16
40
|
|
17
|
-
]
|
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
|
-
|
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
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
[
|
54
|
-
|
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
|
-
["
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
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
|
+
["\\", ['!', md_im_link(['a'],'url') ], 'Escaping images'],
|
164
195
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
196
|
+
["", [md_im_image(['a'],'url')], 'Image no title'],
|
197
|
+
["" ],
|
198
|
+
["![a] ( url )" ],
|
199
|
+
["![a] ( url)" ],
|
169
200
|
|
170
|
-
|
171
|
-
|
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
|
-
["\\", ['!', md_im_link(['a'],'url') ], 'Escaping images'],
|
180
|
-
|
181
|
-
["", [md_im_image(['a'],'url')], 'Image no title'],
|
182
|
-
["" ],
|
183
|
-
["![a] ( url )" ],
|
184
|
-
["![a] ( url)" ],
|
201
|
+
["", [md_im_image(['a'],'url','ti"tle')], 'Image with title'],
|
202
|
+
['' ],
|
185
203
|
|
186
|
-
|
187
|
-
|
204
|
+
["" ],
|
206
|
+
["![a] ('url )" ],
|
188
207
|
|
189
|
-
|
190
|
-
|
191
|
-
|
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
|
-
|
194
|
-
|
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
|
-
|
210
|
-
["a<!-- ", :throw, 'Bad HTML Comment'],
|
227
|
+
["<? <?!--!`3 ?>", [md_server('<?!--!`3')], 'Server directive'],
|
211
228
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
]
|
242
|
+
["l&andrea;", ["l", md_entity('andrea')] ],
|
243
|
+
["&&andrea;", ["&", md_entity('andrea')] ],
|
244
|
+
["&123;;&",[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
|
+
['', [md_im_image(['a'],'url','ti"tle')],
|
250
|
+
"Image with quotes"],
|
251
|
+
['' ],
|
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
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
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
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
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
|
-
|
273
|
-
|
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
|
-
|
284
|
-
|
285
|
-
|
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
|
-
|
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
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
346
|
+
quiet = ARGV.include? 'q'
|
347
|
+
Maruku.new.test_span_parser(verbose, break_on_first, quiet)
|
317
348
|
|
318
349
|
|