wikitext 0.1
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/ext/ary.h +99 -0
- data/ext/depend +22 -0
- data/ext/extconf.rb +23 -0
- data/ext/parser.c +2174 -0
- data/ext/parser.h +31 -0
- data/ext/str.h +135 -0
- data/ext/token.c +109 -0
- data/ext/token.h +95 -0
- data/ext/wikitext.c +60 -0
- data/ext/wikitext.h +30 -0
- data/ext/wikitext_ragel.c +3354 -0
- data/ext/wikitext_ragel.h +17 -0
- data/spec/autolinking_spec.rb +122 -0
- data/spec/blockquote_spec.rb +570 -0
- data/spec/em_spec.rb +97 -0
- data/spec/encoding_spec.rb +124 -0
- data/spec/entity_spec.rb +40 -0
- data/spec/external_link_spec.rb +289 -0
- data/spec/h1_spec.rb +59 -0
- data/spec/h2_spec.rb +59 -0
- data/spec/h3_spec.rb +59 -0
- data/spec/h4_spec.rb +59 -0
- data/spec/h5_spec.rb +59 -0
- data/spec/h6_spec.rb +59 -0
- data/spec/indentation_spec.rb +70 -0
- data/spec/integration_spec.rb +265 -0
- data/spec/internal_link_spec.rb +445 -0
- data/spec/line_endings_spec.rb +81 -0
- data/spec/link_encoding_spec.rb +132 -0
- data/spec/link_sanitizing_spec.rb +228 -0
- data/spec/nowiki_spec.rb +155 -0
- data/spec/p_spec.rb +44 -0
- data/spec/pre_spec.rb +411 -0
- data/spec/regressions_spec.rb +45 -0
- data/spec/spec_helper.rb +77 -0
- data/spec/strong_em_spec.rb +89 -0
- data/spec/strong_spec.rb +99 -0
- data/spec/tokenizing_spec.rb +190 -0
- data/spec/tt_spec.rb +100 -0
- data/spec/ul_spec.rb +307 -0
- data/spec/wikitext_spec.rb +50 -0
- metadata +93 -0
data/spec/em_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright 2007-2008 Wincent Colaiuta
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
17
|
+
require 'wikitext'
|
18
|
+
|
19
|
+
describe Wikitext::Parser, 'parsing <em> spans' do
|
20
|
+
before do
|
21
|
+
@parser = Wikitext::Parser.new
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'marked up using wikitext shorthand' do
|
25
|
+
it 'should recognize paired <em> tokens' do
|
26
|
+
@parser.parse("foo ''bar'' baz").should == "<p>foo <em>bar</em> baz</p>\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should automatically insert missing closing tags' do
|
30
|
+
@parser.parse("foo ''bar").should == "<p>foo <em>bar</em></p>\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should automatically close unclosed spans upon hitting newlines' do
|
34
|
+
@parser.parse("foo ''bar\nbaz").should == "<p>foo <em>bar</em> baz</p>\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should handle (illegal) interleaved spans' do
|
38
|
+
@parser.parse("foo ''bar '''inner'' baz'''").should == "<p>foo <em>bar <strong>inner</strong></em> baz<strong></strong></p>\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should have no effect inside <pre> blocks' do
|
42
|
+
@parser.parse(" ''foo''").should == "<pre>''foo''</pre>\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should have no effect inside <nowiki> spans' do
|
46
|
+
@parser.parse("<nowiki>''foo''</nowiki>").should == "<p>''foo''</p>\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should have no effect if an em (<em>) span is already open" do
|
50
|
+
@parser.parse("foo <em>''bar''</em> baz").should == "<p>foo <em>''bar''</em> baz</p>\n"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'marked up using HTML tags' do
|
55
|
+
it 'should recognized paired <em> tokens' do
|
56
|
+
@parser.parse("foo <em>bar</em> baz").should == "<p>foo <em>bar</em> baz</p>\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should recognize <em> tokens case-insensitively' do
|
60
|
+
@parser.parse("foo <EM>bar</EM> baz").should == "<p>foo <em>bar</em> baz</p>\n"
|
61
|
+
@parser.parse("foo <Em>bar</eM> baz").should == "<p>foo <em>bar</em> baz</p>\n"
|
62
|
+
@parser.parse("foo <eM>bar</Em> baz").should == "<p>foo <em>bar</em> baz</p>\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should automatically insert missing closing tags' do
|
66
|
+
@parser.parse("foo <em>bar").should == "<p>foo <em>bar</em></p>\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should automatically close unclosed spans upon hitting newlines' do
|
70
|
+
@parser.parse("foo <em>bar\nbaz").should == "<p>foo <em>bar</em> baz</p>\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should handle (illegal) interleaved spans' do
|
74
|
+
expected = "<p>foo <em>bar <strong>inner</strong></em> baz</strong></p>\n"
|
75
|
+
@parser.parse("foo <em>bar <strong>inner</em> baz</strong>").should == expected
|
76
|
+
|
77
|
+
expected = "<p>foo <em>bar <strong>inner</strong></em> baz<strong></strong></p>\n"
|
78
|
+
@parser.parse("foo <em>bar '''inner</em> baz'''").should == expected
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should handle (illegal) nested <em> spans' do
|
82
|
+
@parser.parse('foo <em>bar <em>inner</em></em> baz').should == "<p>foo <em>bar <em>inner</em></em> baz</p>\n"
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should have no effect inside <pre> blocks' do
|
86
|
+
@parser.parse(" <em>foo</em>").should == "<pre><em>foo</em></pre>\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should have no effect inside <nowiki> spans' do
|
90
|
+
@parser.parse("<nowiki><em>foo</em></nowiki>").should == "<p><em>foo</em></p>\n"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have no effect if an em ('') span is already open" do
|
94
|
+
@parser.parse("foo ''<em>bar</em>'' baz").should == "<p>foo <em><em>bar</em></em> baz</p>\n"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright 2007-2008 Wincent Colaiuta
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
17
|
+
require 'wikitext'
|
18
|
+
require 'iconv'
|
19
|
+
|
20
|
+
describe Wikitext, 'with invalidly encoded input' do
|
21
|
+
before do
|
22
|
+
@parser = Wikitext::Parser.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should raise an exception for missing second byte' do
|
26
|
+
lambda { @parser.parse(UTF8::Invalid::TWO_BYTES_MISSING_SECOND_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
27
|
+
lambda {
|
28
|
+
@parser.parse('good text' + UTF8::Invalid::TWO_BYTES_MISSING_SECOND_BYTE)
|
29
|
+
}.should raise_error(Wikitext::Parser::Error)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should raise an exception for malformed second byte' do
|
33
|
+
lambda { @parser.parse(UTF8::Invalid::TWO_BYTES_MALFORMED_SECOND_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
34
|
+
lambda {
|
35
|
+
@parser.parse('good text' + UTF8::Invalid::TWO_BYTES_MALFORMED_SECOND_BYTE)
|
36
|
+
}.should raise_error(Wikitext::Parser::Error)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should raise an exception for overlong sequence' do
|
40
|
+
lambda { @parser.parse(UTF8::Invalid::OVERLONG) }.should raise_error(Wikitext::Parser::Error)
|
41
|
+
lambda {
|
42
|
+
@parser.parse('good text' + UTF8::Invalid::OVERLONG)
|
43
|
+
}.should raise_error(Wikitext::Parser::Error)
|
44
|
+
|
45
|
+
# alternate
|
46
|
+
lambda { @parser.parse(UTF8::Invalid::OVERLONG_ALT) }.should raise_error(Wikitext::Parser::Error)
|
47
|
+
lambda {
|
48
|
+
@parser.parse('good text' + UTF8::Invalid::OVERLONG_ALT)
|
49
|
+
}.should raise_error(Wikitext::Parser::Error)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should raise an exception for missing second byte in three-byte sequence' do
|
53
|
+
lambda { @parser.parse(UTF8::Invalid::THREE_BYTES_MISSING_SECOND_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
54
|
+
lambda {
|
55
|
+
@parser.parse('good text' + UTF8::Invalid::THREE_BYTES_MISSING_SECOND_BYTE)
|
56
|
+
}.should raise_error(Wikitext::Parser::Error)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should raise an exception for missing third byte in three-byte sequence' do
|
60
|
+
lambda { @parser.parse(UTF8::Invalid::THREE_BYTES_MISSING_THIRD_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
61
|
+
lambda {
|
62
|
+
@parser.parse('good text' + UTF8::Invalid::THREE_BYTES_MISSING_THIRD_BYTE)
|
63
|
+
}.should raise_error(Wikitext::Parser::Error)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should raise an exception for malformed second byte in three-byte sequence' do
|
67
|
+
lambda { @parser.parse(UTF8::Invalid::THREE_BYTES_MALFORMED_SECOND_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
68
|
+
lambda {
|
69
|
+
@parser.parse('good text' + UTF8::Invalid::THREE_BYTES_MALFORMED_SECOND_BYTE)
|
70
|
+
}.should raise_error(Wikitext::Parser::Error)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should raise an exception for malformed third byte in three-byte sequence' do
|
74
|
+
lambda { @parser.parse(UTF8::Invalid::THREE_BYTES_MALFORMED_THIRD_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
75
|
+
lambda {
|
76
|
+
@parser.parse('good text' + UTF8::Invalid::THREE_BYTES_MALFORMED_THIRD_BYTE)
|
77
|
+
}.should raise_error(Wikitext::Parser::Error)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should raise an exception for missing second byte in four-byte sequence' do
|
81
|
+
lambda { @parser.parse(UTF8::Invalid::FOUR_BYTES_MISSING_SECOND_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
82
|
+
lambda {
|
83
|
+
@parser.parse('good text' + UTF8::Invalid::FOUR_BYTES_MISSING_SECOND_BYTE)
|
84
|
+
}.should raise_error(Wikitext::Parser::Error)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should raise an exception for missing third byte in four-byte sequence' do
|
88
|
+
lambda { @parser.parse(UTF8::Invalid::FOUR_BYTES_MISSING_THIRD_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
89
|
+
lambda {
|
90
|
+
@parser.parse('good text' + UTF8::Invalid::FOUR_BYTES_MISSING_THIRD_BYTE)
|
91
|
+
}.should raise_error(Wikitext::Parser::Error)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should raise an exception for missing fourth byte in four-byte sequence' do
|
95
|
+
lambda { @parser.parse(UTF8::Invalid::FOUR_BYTES_MISSING_FOURTH_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
96
|
+
lambda {
|
97
|
+
@parser.parse('good text' + UTF8::Invalid::FOUR_BYTES_MISSING_FOURTH_BYTE)
|
98
|
+
}.should raise_error(Wikitext::Parser::Error)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should raise an exception for illegal first byte in four-byte sequence' do
|
102
|
+
lambda { @parser.parse(UTF8::Invalid::FOUR_BYTES_ILLEGAL_FIRST_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
103
|
+
lambda {
|
104
|
+
@parser.parse('good text' + UTF8::Invalid::FOUR_BYTES_ILLEGAL_FIRST_BYTE)
|
105
|
+
}.should raise_error(Wikitext::Parser::Error)
|
106
|
+
|
107
|
+
lambda { @parser.parse(UTF8::Invalid::FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT) }.should raise_error(Wikitext::Parser::Error)
|
108
|
+
lambda {
|
109
|
+
@parser.parse('good text' + UTF8::Invalid::FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT)
|
110
|
+
}.should raise_error(Wikitext::Parser::Error)
|
111
|
+
|
112
|
+
lambda { @parser.parse(UTF8::Invalid::FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT2) }.should raise_error(Wikitext::Parser::Error)
|
113
|
+
lambda {
|
114
|
+
@parser.parse('good text' + UTF8::Invalid::FOUR_BYTES_ILLEGAL_FIRST_BYTE_ALT2)
|
115
|
+
}.should raise_error(Wikitext::Parser::Error)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should raise an exception for unexpected bytes' do
|
119
|
+
lambda { @parser.parse(UTF8::Invalid::UNEXPECTED_BYTE) }.should raise_error(Wikitext::Parser::Error)
|
120
|
+
lambda {
|
121
|
+
@parser.parse('good text' + UTF8::Invalid::UNEXPECTED_BYTE)
|
122
|
+
}.should raise_error(Wikitext::Parser::Error)
|
123
|
+
end
|
124
|
+
end
|
data/spec/entity_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright 2007-2008 Wincent Colaiuta
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
17
|
+
require 'wikitext'
|
18
|
+
|
19
|
+
describe Wikitext::Parser, 'parsing entities' do
|
20
|
+
before do
|
21
|
+
@parser = Wikitext::Parser.new
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should pass numeric (decimal) entities through unchanged' do
|
25
|
+
@parser.parse('€').should == "<p>€</p>\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should normalize case variations in hexadecimal entities' do
|
29
|
+
@parser.parse('€').should == "<p>€</p>\n"
|
30
|
+
@parser.parse('€').should == "<p>€</p>\n"
|
31
|
+
@parser.parse('€').should == "<p>€</p>\n"
|
32
|
+
@parser.parse('€').should == "<p>€</p>\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should pass named entities through unchanged' do
|
36
|
+
@parser.parse('Á').should == "<p>Á</p>\n" # these are two different entities
|
37
|
+
@parser.parse('á').should == "<p>á</p>\n" # ie. they are case sensitive
|
38
|
+
@parser.parse('€').should == "<p>€</p>\n"
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,289 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright 2007-2008 Wincent Colaiuta
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
17
|
+
require 'wikitext'
|
18
|
+
|
19
|
+
describe Wikitext::Parser, 'external links' do
|
20
|
+
before do
|
21
|
+
@parser = Wikitext::Parser.new
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should format valid external HTTP links' do
|
25
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google</a></p>\n}
|
26
|
+
@parser.parse('[http://google.com/ Google]').should == expected
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should format valid external HTTPS links' do
|
30
|
+
expected = %Q{<p><a href="https://google.com/" class="external">Google</a></p>\n}
|
31
|
+
@parser.parse('[https://google.com/ Google]').should == expected
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should format valid external FTP links' do
|
35
|
+
expected = %Q{<p><a href="ftp://google.com/" class="external">Google</a></p>\n}
|
36
|
+
@parser.parse('[ftp://google.com/ Google]').should == expected
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should format valid external SVN links' do
|
40
|
+
expected = %Q{<p><a href="svn://google.com/" class="external">Google</a></p>\n}
|
41
|
+
@parser.parse('[svn://google.com/ Google]').should == expected
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should format valid external mailto links' do
|
45
|
+
# although note in this case the CSS class is "external" rather than "mailto"
|
46
|
+
# this is because we're matching this as a (generic) URI rather than an email address
|
47
|
+
expected = %Q{<p><a href="mailto:user@example.com" class="external">john</a></p>\n}
|
48
|
+
@parser.parse('[mailto:user@example.com john]').should == expected
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should treat runs of spaces after the link target as a single space' do
|
52
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google</a></p>\n}
|
53
|
+
@parser.parse('[http://google.com/ Google]').should == expected
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should not treat runs of spaces within the link text as a single space' do
|
57
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google search</a></p>\n}
|
58
|
+
@parser.parse('[http://google.com/ Google search]').should == expected
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should format a link with emphasis in the link text' do
|
62
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google <em>rocks</em></a></p>\n}
|
63
|
+
@parser.parse("[http://google.com/ Google ''rocks'']").should == expected
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should automatically close unmatched '' tags in the link text" do
|
67
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google <em>SOC</em></a></p>\n}
|
68
|
+
@parser.parse("[http://google.com/ Google ''SOC]").should == expected
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should format a link with strong formatting in the link text' do
|
72
|
+
expected = %Q{<p><a href="http://google.com/" class="external"><strong>Google</strong> rocks</a></p>\n}
|
73
|
+
@parser.parse("[http://google.com/ '''Google''' rocks]").should == expected
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should automatically close unmatched ''' tags in the link text" do
|
77
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google <strong>SOC</strong></a></p>\n}
|
78
|
+
@parser.parse("[http://google.com/ Google '''SOC]").should == expected
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should format a link with <tt></tt> tags in the link text' do
|
82
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google <tt>SOC</tt></a></p>\n}
|
83
|
+
@parser.parse("[http://google.com/ Google <tt>SOC</tt>]").should == expected
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should automatically close unmatched <tt> tags in the link text' do
|
87
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google <tt>SOC</tt></a></p>\n}
|
88
|
+
@parser.parse("[http://google.com/ Google <tt>SOC]").should == expected
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should format a link with strong and emphasis in the link text' do
|
92
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google <strong><em>rocks</em></strong></a></p>\n}
|
93
|
+
@parser.parse("[http://google.com/ Google '''''rocks''''']").should == expected
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should automatically close unmatched ''''' tags in the link text" do
|
97
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google <strong><em>SOC</em></strong></a></p>\n}
|
98
|
+
@parser.parse("[http://google.com/ Google '''''SOC]").should == expected
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should respect "<nowiki></nowiki>" tags inside the link text' do
|
102
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google ] rocks</a></p>\n}
|
103
|
+
@parser.parse("[http://google.com/ Google <nowiki>]</nowiki> rocks]").should == expected # was a bug
|
104
|
+
|
105
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google [ rocks</a></p>\n}
|
106
|
+
@parser.parse("[http://google.com/ Google <nowiki>[</nowiki> rocks]").should == expected # was a bug
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should pass "[" in link text through literally' do
|
110
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google [ rocks</a></p>\n}
|
111
|
+
@parser.parse("[http://google.com/ Google [ rocks]").should == expected # was a bug
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should pass "[[" in link text through literally' do
|
115
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google [[ rocks</a></p>\n}
|
116
|
+
@parser.parse("[http://google.com/ Google [[ rocks]").should == expected # was a bug
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should pass "]]" in link text through literally' do
|
120
|
+
# note how "]]" is treated as a single token, not as a "]" which closes the link followed by another ("] rocks]")
|
121
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google ]] rocks</a></p>\n}
|
122
|
+
@parser.parse("[http://google.com/ Google ]] rocks]").should == expected # was a bug
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should pass through ASCII entities in the link text' do
|
126
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google "SOC"</a></p>\n} # QUOT
|
127
|
+
@parser.parse(%Q{[http://google.com/ Google "SOC"]}).should == expected
|
128
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google <SOC></a></p>\n} # LESS, GREATER
|
129
|
+
@parser.parse(%Q{[http://google.com/ Google <SOC>]}).should == expected
|
130
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google & SOC</a></p>\n} # AMP
|
131
|
+
@parser.parse(%Q{[http://google.com/ Google & SOC]}).should == expected
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should pass through named entities in the link text' do
|
135
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google €</a></p>\n}
|
136
|
+
@parser.parse(%Q{[http://google.com/ Google €]}).should == expected
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should pass through decimal entities in the link text' do
|
140
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google €</a></p>\n}
|
141
|
+
@parser.parse(%Q{[http://google.com/ Google €]}).should == expected
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should pass through hexadecimal entities in the link text' do
|
145
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google €</a></p>\n}
|
146
|
+
@parser.parse(%Q{[http://google.com/ Google €]}).should == expected
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should convert non-ASCII characters in the link text into entities' do
|
150
|
+
expected = %Q{<p><a href="http://google.com/" class="external">Google €</a></p>\n}
|
151
|
+
@parser.parse(%Q{[http://google.com/ Google €]}).should == expected
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should pass through unexpected external link end tokens literally' do
|
155
|
+
@parser.parse('foo ] bar').should == "<p>foo ] bar</p>\n" # in plain scope
|
156
|
+
@parser.parse("foo '']'' bar").should == "<p>foo <em>]</em> bar</p>\n" # in EM scope
|
157
|
+
@parser.parse("foo ''']''' bar").should == "<p>foo <strong>]</strong> bar</p>\n" # in STRONG scope
|
158
|
+
@parser.parse("foo ''''']''''' bar").should == "<p>foo <strong><em>]</em></strong> bar</p>\n" # in STRONG_EM scope
|
159
|
+
@parser.parse('foo <tt>]</tt> bar').should == "<p>foo <tt>]</tt> bar</p>\n" # in TT scope
|
160
|
+
@parser.parse('= foo ] bar =').should == "<h1>foo ] bar</h1>\n" # in H1 scope
|
161
|
+
@parser.parse('== foo ] bar ==').should == "<h2>foo ] bar</h2>\n" # in H2 scope
|
162
|
+
@parser.parse('=== foo ] bar ===').should == "<h3>foo ] bar</h3>\n" # in H3 scope
|
163
|
+
@parser.parse('==== foo ] bar ====').should == "<h4>foo ] bar</h4>\n" # in H4 scope
|
164
|
+
@parser.parse('===== foo ] bar =====').should == "<h5>foo ] bar</h5>\n" # in H5 scope
|
165
|
+
@parser.parse('====== foo ] bar ======').should == "<h6>foo ] bar</h6>\n" # in H6 scope
|
166
|
+
@parser.parse('> ]').should == "<blockquote>\n <p>]</p>\n</blockquote>\n" # in BLOCKQUOTE scope
|
167
|
+
end
|
168
|
+
|
169
|
+
describe 'questionable links' do
|
170
|
+
it 'should handle links which contain an embedded [ character' do
|
171
|
+
# note that [ is allowed in the link text, although the result may be unexpected to the user
|
172
|
+
expected = %Q{<p><a href="http://google.com/" class="external">[hello</a></p>\n}
|
173
|
+
@parser.parse("[http://google.com/ [hello]").should == expected
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should handle links which contain an embedded ] character' do
|
177
|
+
# note how the first ] terminates the link
|
178
|
+
expected = %Q{<p><a href="http://google.com/" class="external">[hello</a> world]</p>\n}
|
179
|
+
@parser.parse("[http://google.com/ [hello] world]").should == expected
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should handle links which contain an embedded [[ character' do
|
183
|
+
# note that [[ is allowed in the link text
|
184
|
+
expected = %Q{<p><a href="http://google.com/" class="external">[[hello</a></p>\n}
|
185
|
+
@parser.parse("[http://google.com/ [[hello]").should == expected
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should handle links which contain an embedded ]] character' do
|
189
|
+
# note how this time ]] does not terminate the link because it is tokenized as LINK_END rather than EXT_LINK_END
|
190
|
+
expected = %Q{<p><a href="http://google.com/" class="external">[[hello]] world</a></p>\n}
|
191
|
+
@parser.parse("[http://google.com/ [[hello]] world]").should == expected
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should allow URIs in the link text' do
|
195
|
+
# not sure why you'd want to do this, but...
|
196
|
+
expected = %Q{<p><a href="http://example.net/" class="external">hello http://example.com/ world</a></p>\n}
|
197
|
+
@parser.parse('[http://example.net/ hello http://example.com/ world]').should == expected
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe 'invalid links' do
|
202
|
+
it "should pass through links which don't have a valid target" do
|
203
|
+
expected = "<p>[well]</p>\n"
|
204
|
+
@parser.parse("[well]").should == expected
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should pass through links which don't have any target" do
|
208
|
+
expected = "<p>[]</p>\n"
|
209
|
+
@parser.parse('[]').should == expected
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'should pass through unterminated links (EOF)' do
|
213
|
+
expected = "<p>[</p>\n"
|
214
|
+
@parser.parse('[').should == expected
|
215
|
+
|
216
|
+
expected = "<p>[well</p>\n"
|
217
|
+
@parser.parse("[well").should == expected
|
218
|
+
|
219
|
+
expected = %Q{<p>[<a href="http://example.com/" class="external">http://example.com/</a></p>\n}
|
220
|
+
@parser.parse("[http://example.com/").should == expected
|
221
|
+
|
222
|
+
expected = %Q{<p>[<a href="http://example.com/" class="external">http://example.com/</a> </p>\n}
|
223
|
+
@parser.parse("[http://example.com/ ").should == expected
|
224
|
+
|
225
|
+
expected = %Q{<p>[<a href="http://example.com/" class="external">http://example.com/</a> visit</p>\n}
|
226
|
+
@parser.parse("[http://example.com/ visit").should == expected # was a bug
|
227
|
+
|
228
|
+
expected = %Q{<h6>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h6>\n}
|
229
|
+
@parser.parse("====== [http://example.com/ visit").should == expected # was a bug
|
230
|
+
|
231
|
+
expected = %Q{<h5>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h5>\n}
|
232
|
+
@parser.parse("===== [http://example.com/ visit").should == expected # was a bug
|
233
|
+
|
234
|
+
expected = %Q{<h4>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h4>\n}
|
235
|
+
@parser.parse("==== [http://example.com/ visit").should == expected # was a bug
|
236
|
+
|
237
|
+
expected = %Q{<h3>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h3>\n}
|
238
|
+
@parser.parse("=== [http://example.com/ visit").should == expected # was a bug
|
239
|
+
|
240
|
+
expected = %Q{<h2>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h2>\n}
|
241
|
+
@parser.parse("== [http://example.com/ visit").should == expected # was a bug
|
242
|
+
|
243
|
+
expected = %Q{<h1>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h1>\n}
|
244
|
+
@parser.parse("= [http://example.com/ visit").should == expected # was a bug
|
245
|
+
|
246
|
+
expected = %Q{<p>[<a href="http://example.com/" class="external">http://example.com/</a> ...</p>\n}
|
247
|
+
@parser.parse("[http://example.com/ <nowiki>...\n").should == expected
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'should pass through unterminated links (end-of-line)' do
|
251
|
+
expected = "<p>[</p>\n"
|
252
|
+
@parser.parse("[\n").should == expected
|
253
|
+
|
254
|
+
expected = "<p>[well</p>\n"
|
255
|
+
@parser.parse("[well\n").should == expected
|
256
|
+
|
257
|
+
expected = %Q{<p>[<a href="http://example.com/" class="external">http://example.com/</a></p>\n}
|
258
|
+
@parser.parse("[http://example.com/\n").should == expected
|
259
|
+
|
260
|
+
expected = %Q{<p>[<a href="http://example.com/" class="external">http://example.com/</a> </p>\n}
|
261
|
+
@parser.parse("[http://example.com/ \n").should == expected
|
262
|
+
|
263
|
+
expected = %Q{<p>[<a href="http://example.com/" class="external">http://example.com/</a> visit</p>\n}
|
264
|
+
@parser.parse("[http://example.com/ visit\n").should == expected # was a bug
|
265
|
+
|
266
|
+
expected = %Q{<h6>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h6>\n}
|
267
|
+
@parser.parse("====== [http://example.com/ visit\n").should == expected # was a bug
|
268
|
+
|
269
|
+
expected = %Q{<h5>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h5>\n}
|
270
|
+
@parser.parse("===== [http://example.com/ visit\n").should == expected # was a bug
|
271
|
+
|
272
|
+
expected = %Q{<h4>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h4>\n}
|
273
|
+
@parser.parse("==== [http://example.com/ visit\n").should == expected # was a bug
|
274
|
+
|
275
|
+
expected = %Q{<h3>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h3>\n}
|
276
|
+
@parser.parse("=== [http://example.com/ visit\n").should == expected # was a bug
|
277
|
+
|
278
|
+
expected = %Q{<h2>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h2>\n}
|
279
|
+
@parser.parse("== [http://example.com/ visit\n").should == expected # was a bug
|
280
|
+
|
281
|
+
expected = %Q{<h1>[<a href="http://example.com/" class="external">http://example.com/</a> visit</h1>\n}
|
282
|
+
@parser.parse("= [http://example.com/ visit\n").should == expected # was a bug
|
283
|
+
|
284
|
+
# here's a slightly more complicated example using a blockquote
|
285
|
+
expected = %Q{<blockquote>\n <p>[<a href="http://google.com/" class="external">http://google.com/</a></p>\n</blockquote>\n}
|
286
|
+
@parser.parse("> [http://google.com/\n").should == expected # was a bug
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|