trac-wiki 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/trac_wiki/parser.rb +4 -2
- data/lib/trac_wiki/version.rb +1 -1
- data/test/parser_test.rb +139 -139
- metadata +1 -1
data/lib/trac_wiki/parser.rb
CHANGED
@@ -13,8 +13,8 @@ require 'uri'
|
|
13
13
|
# **Bold text**
|
14
14
|
# ''Italic text''
|
15
15
|
# [[Links]]
|
16
|
-
# ||=Table
|
17
|
-
# || Table|| Cells
|
16
|
+
# ||=Table=||=Heading=||
|
17
|
+
# || Table || Cells ||
|
18
18
|
# [[Image(image.png)]]
|
19
19
|
#
|
20
20
|
# The simplest interface is TracWiki.render. The default handling of
|
@@ -111,6 +111,8 @@ module TracWiki
|
|
111
111
|
tagi = @stacki.pop
|
112
112
|
if tag == 'strongem'
|
113
113
|
@out << '</em></strong>'
|
114
|
+
elsif tag == 'p'
|
115
|
+
@out << "</p>\n"
|
114
116
|
else
|
115
117
|
@out << "</#{tag}>"
|
116
118
|
end
|
data/lib/trac_wiki/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -13,8 +13,8 @@ end
|
|
13
13
|
describe TracWiki::Parser do
|
14
14
|
it 'should parse bold' do
|
15
15
|
# Bold can be used inside paragraphs
|
16
|
-
tc "<p>This <strong>is</strong> bold</p
|
17
|
-
tc "<p>This <strong>is</strong> bold and <strong>bold</strong>ish</p
|
16
|
+
tc "<p>This <strong>is</strong> bold</p>\n", "This **is** bold"
|
17
|
+
tc "<p>This <strong>is</strong> bold and <strong>bold</strong>ish</p>\n", "This **is** bold and **bold**ish"
|
18
18
|
|
19
19
|
# Bold can be used inside list items
|
20
20
|
tc "<ul><li>This is <strong>bold</strong></li></ul>", "* This is **bold**"
|
@@ -24,11 +24,11 @@ describe TracWiki::Parser do
|
|
24
24
|
"||This is **bold**||")
|
25
25
|
|
26
26
|
# Links can appear inside bold text:
|
27
|
-
tc("<p>A bold link: <strong><a href=\"http://example.org/\">http://example.org/</a> nice! </strong></p
|
27
|
+
tc("<p>A bold link: <strong><a href=\"http://example.org/\">http://example.org/</a> nice! </strong></p>\n",
|
28
28
|
"A bold link: **http://example.org/ nice! **")
|
29
29
|
|
30
30
|
# Bold will end at the end of paragraph
|
31
|
-
tc "<p>This <strong>is bold</strong></p
|
31
|
+
tc "<p>This <strong>is bold</strong></p>\n", "This **is bold"
|
32
32
|
|
33
33
|
# Bold will end at the end of list items
|
34
34
|
tc("<ul><li>Item <strong>bold</strong></li><li>Item normal</li></ul>",
|
@@ -39,36 +39,36 @@ describe TracWiki::Parser do
|
|
39
39
|
"||Item **bold||Another **bold||")
|
40
40
|
|
41
41
|
# Bold should not cross paragraphs
|
42
|
-
tc("<p>This <strong>is</strong></p
|
42
|
+
tc("<p>This <strong>is</strong></p>\n<p>bold<strong> maybe</strong></p>\n",
|
43
43
|
"This **is\n\nbold** maybe")
|
44
44
|
|
45
45
|
# Bold should be able to cross lines
|
46
|
-
tc "<p>This <strong>is bold</strong></p
|
46
|
+
tc "<p>This <strong>is bold</strong></p>\n", "This **is\nbold**"
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should parse bolditalic' do
|
50
|
-
tc
|
51
|
-
tc
|
52
|
-
tc
|
53
|
-
tc
|
54
|
-
#fuj tc '<p>This is <strong><em>bolditallic</em></strong>.</p
|
50
|
+
tc "<p>This is <strong><em>bolditallic</em></strong>.</p>\n", "This is '''''bolditallic'''''."
|
51
|
+
tc "<p>This is <strong> <em>bolditallic</em> </strong>.</p>\n", "This is ''' ''bolditallic'' '''."
|
52
|
+
tc "<p>This is <em> <strong>bolditallic</strong> </em>.</p>\n", "This is '' '''bolditallic''' ''."
|
53
|
+
tc "<p>This is <strong>bold</strong>.</p>\n", "This is '''bold'''."
|
54
|
+
#fuj tc '<p>This is <strong><em>bolditallic</em></strong>.</p>\n', "This is **''bolditallic**''."
|
55
55
|
end
|
56
56
|
it 'should parse monospace' do
|
57
|
-
tc "<p>This is <tt>monospace</tt>.</p
|
58
|
-
tc "<p>This is <tt>mon**o**space</tt>.</p
|
59
|
-
tc "<p>This is <tt>mon<o>space</tt>.</p
|
60
|
-
tc "<p>This is <tt>mon''o''space</tt>.</p
|
61
|
-
tc "<p>This is <tt>mon''o''space</tt>.</p
|
62
|
-
tc "<p>This is <tt>mon{{o}}space</tt>.</p
|
63
|
-
tc "<p>This is <tt>mon``o''space</tt>.</p
|
64
|
-
tc "<p>This is <tt>mon{{o}}space</tt>.</p
|
57
|
+
tc "<p>This is <tt>monospace</tt>.</p>\n", "This is {{{monospace}}}."
|
58
|
+
tc "<p>This is <tt>mon**o**space</tt>.</p>\n", "This is {{{mon**o**space}}}."
|
59
|
+
tc "<p>This is <tt>mon<o>space</tt>.</p>\n", "This is {{{mon<o>space}}}."
|
60
|
+
tc "<p>This is <tt>mon''o''space</tt>.</p>\n", "This is {{{mon''o''space}}}."
|
61
|
+
tc "<p>This is <tt>mon''o''space</tt>.</p>\n", "This is `mon''o''space`."
|
62
|
+
tc "<p>This is <tt>mon{{o}}space</tt>.</p>\n", "This is {{{mon{{o}}space}}}."
|
63
|
+
tc "<p>This is <tt>mon``o''space</tt>.</p>\n", "This is {{{mon``o''space}}}."
|
64
|
+
tc "<p>This is <tt>mon{{o}}space</tt>.</p>\n", "This is `mon{{o}}space`."
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'should parse italic' do
|
68
68
|
# Italic can be used inside paragraphs
|
69
|
-
tc("<p>This <em>is</em> italic</p
|
69
|
+
tc("<p>This <em>is</em> italic</p>\n",
|
70
70
|
"This ''is'' italic")
|
71
|
-
tc("<p>This <em>is</em> italic and <em>italic</em>ish</p
|
71
|
+
tc("<p>This <em>is</em> italic and <em>italic</em>ish</p>\n",
|
72
72
|
"This ''is'' italic and ''italic''ish")
|
73
73
|
|
74
74
|
# Italic can be used inside list items
|
@@ -79,11 +79,11 @@ describe TracWiki::Parser do
|
|
79
79
|
"||This is ''italic''||")
|
80
80
|
|
81
81
|
# Links can appear inside italic text:
|
82
|
-
tc("<p>A italic link: <em><a href=\"http://example.org/\">http://example.org/</a> nice! </em></p
|
82
|
+
tc("<p>A italic link: <em><a href=\"http://example.org/\">http://example.org/</a> nice! </em></p>\n",
|
83
83
|
"A italic link: ''http://example.org/ nice! ''")
|
84
84
|
|
85
85
|
# Italic will end at the end of paragraph
|
86
|
-
tc "<p>This <em>is italic</em></p
|
86
|
+
tc "<p>This <em>is italic</em></p>\n", "This ''is italic"
|
87
87
|
|
88
88
|
# Italic will end at the end of list items
|
89
89
|
tc("<ul><li>Item <em>italic</em></li><li>Item normal</li></ul>",
|
@@ -94,22 +94,22 @@ describe TracWiki::Parser do
|
|
94
94
|
"||Item ''italic||Another ''italic")
|
95
95
|
|
96
96
|
# Italic should not cross paragraphs
|
97
|
-
tc("<p>This <em>is</em></p
|
97
|
+
tc("<p>This <em>is</em></p>\n<p>italic<em> maybe</em></p>\n",
|
98
98
|
"This ''is\n\nitalic'' maybe")
|
99
99
|
|
100
100
|
# Italic should be able to cross lines
|
101
|
-
tc "<p>This <em>is italic</em></p
|
101
|
+
tc "<p>This <em>is italic</em></p>\n", "This ''is\nitalic''"
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should parse bold italics' do
|
105
105
|
# By example
|
106
|
-
tc "<p><strong><em>bold italics</em></strong></p
|
106
|
+
tc "<p><strong><em>bold italics</em></strong></p>\n", "**''bold italics''**"
|
107
107
|
|
108
108
|
# By example
|
109
|
-
tc "<p><em><strong>bold italics</strong></em></p
|
109
|
+
tc "<p><em><strong>bold italics</strong></em></p>\n", "''**bold italics**''"
|
110
110
|
|
111
111
|
# By example
|
112
|
-
tc "<p><em>This is <strong>also</strong> good.</em></p
|
112
|
+
tc "<p><em>This is <strong>also</strong> good.</em></p>\n", "''This is **also** good.''"
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'should parse headings' do
|
@@ -142,105 +142,105 @@ describe TracWiki::Parser do
|
|
142
142
|
|
143
143
|
# WARNING: !! XXX doesn't specify if text after closing equal signs
|
144
144
|
# !!becomes part of the heading or invalidates the entire heading.
|
145
|
-
# tc "<p> == Heading 2 == foo</p
|
145
|
+
# tc "<p> == Heading 2 == foo</p>\n", " == Heading 2 == foo"
|
146
146
|
tc "<h2>Heading 2 == foo</h2>", " == Heading 2 == foo"
|
147
147
|
|
148
148
|
# Line must start with equal sign
|
149
|
-
tc "<p>foo = Heading 1 =</p
|
149
|
+
tc "<p>foo = Heading 1 =</p>\n", "foo = Heading 1 ="
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'should parse links' do
|
153
153
|
# Links
|
154
|
-
tc "<p><a href=\"link\">link</a></p
|
154
|
+
tc "<p><a href=\"link\">link</a></p>\n", "[[link]]"
|
155
155
|
|
156
156
|
# Links can appear in paragraphs (i.e. inline item)
|
157
|
-
tc "<p>Hello, <a href=\"world\">world</a></p
|
157
|
+
tc "<p>Hello, <a href=\"world\">world</a></p>\n", "Hello, [[world]]"
|
158
158
|
|
159
159
|
# Named links
|
160
|
-
tc "<p><a href=\"MyBigPage\">Go to my page</a></p
|
160
|
+
tc "<p><a href=\"MyBigPage\">Go to my page</a></p>\n", "[[MyBigPage|Go to my page]]"
|
161
161
|
|
162
162
|
# URLs
|
163
|
-
tc "<p><a href=\"http://www.example.org/\">http://www.example.org/</a></p
|
163
|
+
tc "<p><a href=\"http://www.example.org/\">http://www.example.org/</a></p>\n", "[[http://www.example.org/]]"
|
164
164
|
|
165
165
|
# Single punctuation characters at the end of URLs
|
166
166
|
# should not be considered a part of the URL.
|
167
167
|
[',','.','?','!',':',';','\'','"'].each do |punct|
|
168
168
|
esc_punct = CGI::escapeHTML(punct)
|
169
|
-
tc "<p><a href=\"http://www.example.org/\">http://www.example.org/</a>#{esc_punct}</p
|
169
|
+
tc "<p><a href=\"http://www.example.org/\">http://www.example.org/</a>#{esc_punct}</p>\n", "http://www.example.org/#{punct}"
|
170
170
|
end
|
171
171
|
# Nameds URLs (by example)
|
172
|
-
tc("<p><a href=\"http://www.example.org/\">Visit the Example website</a></p
|
172
|
+
tc("<p><a href=\"http://www.example.org/\">Visit the Example website</a></p>\n",
|
173
173
|
"[[http://www.example.org/|Visit the Example website]]")
|
174
174
|
|
175
175
|
# WRNING: Parsing markup within a link is optional
|
176
|
-
tc "<p><a href=\"Weird+Stuff\"><strong>Weird</strong> <em>Stuff</em></a></p
|
177
|
-
#tc("<p><a href=\"http://example.org/\"><img src='image.jpg'/></a></p
|
176
|
+
tc "<p><a href=\"Weird+Stuff\"><strong>Weird</strong> <em>Stuff</em></a></p>\n", "[[Weird Stuff|**Weird** ''Stuff'']]"
|
177
|
+
#tc("<p><a href=\"http://example.org/\"><img src='image.jpg'/></a></p>\n", "[[http://example.org/|{{image.jpg}}]]")
|
178
178
|
|
179
179
|
# Inside bold
|
180
|
-
tc "<p><strong><a href=\"link\">link</a></strong></p
|
180
|
+
tc "<p><strong><a href=\"link\">link</a></strong></p>\n", "**[[link]]**"
|
181
181
|
|
182
182
|
# Whitespace inside [[ ]] should be ignored
|
183
|
-
tc("<p><a href=\"link\">link</a></p
|
184
|
-
tc("<p><a href=\"link+me\">link me</a></p
|
185
|
-
tc("<p><a href=\"http://dot.com/\">dot.com</a></p
|
186
|
-
tc("<p><a href=\"http://dot.com/\">dot.com</a></p
|
183
|
+
tc("<p><a href=\"link\">link</a></p>\n", "[[ link ]]")
|
184
|
+
tc("<p><a href=\"link+me\">link me</a></p>\n", "[[ link me ]]")
|
185
|
+
tc("<p><a href=\"http://dot.com/\">dot.com</a></p>\n", "[[ http://dot.com/ \t| \t dot.com ]]")
|
186
|
+
tc("<p><a href=\"http://dot.com/\">dot.com</a></p>\n", "[[ http://dot.com/ | dot.com ]]")
|
187
187
|
end
|
188
188
|
|
189
189
|
it 'should parse freestanding urls' do
|
190
190
|
# Free-standing URL's should be turned into links
|
191
|
-
tc "<p><a href=\"http://www.example.org/\">http://www.example.org/</a></p
|
191
|
+
tc "<p><a href=\"http://www.example.org/\">http://www.example.org/</a></p>\n", "http://www.example.org/"
|
192
192
|
|
193
193
|
# URL ending in .
|
194
|
-
tc "<p>Text <a href=\"http://example.org\">http://example.org</a>. other text</p
|
194
|
+
tc "<p>Text <a href=\"http://example.org\">http://example.org</a>. other text</p>\n", "Text http://example.org. other text"
|
195
195
|
|
196
196
|
# URL ending in ),
|
197
|
-
tc "<p>Text (<a href=\"http://example.org\">http://example.org</a>), other text</p
|
197
|
+
tc "<p>Text (<a href=\"http://example.org\">http://example.org</a>), other text</p>\n", "Text (http://example.org), other text"
|
198
198
|
|
199
199
|
# URL ending in ).
|
200
|
-
tc "<p>Text (<a href=\"http://example.org\">http://example.org</a>). other text</p
|
200
|
+
tc "<p>Text (<a href=\"http://example.org\">http://example.org</a>). other text</p>\n", "Text (http://example.org). other text"
|
201
201
|
|
202
202
|
# URL ending in ).
|
203
|
-
tc "<p>Text (<a href=\"http://example.org\">http://example.org</a>).</p
|
203
|
+
tc "<p>Text (<a href=\"http://example.org\">http://example.org</a>).</p>\n", "Text (http://example.org)."
|
204
204
|
|
205
205
|
# URL ending in )
|
206
|
-
tc "<p>Text (<a href=\"http://example.org\">http://example.org</a>)</p
|
206
|
+
tc "<p>Text (<a href=\"http://example.org\">http://example.org</a>)</p>\n", "Text (http://example.org)"
|
207
207
|
end
|
208
208
|
|
209
209
|
it 'should parse paragraphs' do
|
210
210
|
# One or more blank lines end paragraphs.
|
211
|
-
tc "<p>This is my text.</p
|
212
|
-
tc "<p>This is my text.</p
|
213
|
-
tc "<p>This is my text.</p
|
211
|
+
tc "<p>This is my text.</p>\n<p>This is more text.</p>\n", "This is\nmy text.\n\nThis is\nmore text."
|
212
|
+
tc "<p>This is my text.</p>\n<p>This is more text.</p>\n", "This is\nmy text.\n\n\nThis is\nmore text."
|
213
|
+
tc "<p>This is my text.</p>\n<p>This is more text.</p>\n", "This is\nmy text.\n\n\n\nThis is\nmore text."
|
214
214
|
|
215
215
|
# A list end paragraphs too.
|
216
|
-
tc "<p>Hello</p
|
216
|
+
tc "<p>Hello</p>\n<ul><li>Item</li></ul>", "Hello\n* Item\n"
|
217
217
|
|
218
218
|
# A table end paragraphs too.
|
219
|
-
tc "<p>Hello</p
|
219
|
+
tc "<p>Hello</p>\n<table><tr><td>Cell</td></tr></table>", "Hello\n||Cell||"
|
220
220
|
|
221
221
|
# A nowiki end paragraphs too.
|
222
|
-
tc "<p>Hello</p
|
222
|
+
tc "<p>Hello</p>\n<pre>nowiki</pre>", "Hello\n{{{\nnowiki\n}}}\n"
|
223
223
|
|
224
224
|
# WARNING: A heading ends a paragraph (not specced)
|
225
|
-
tc "<p>Hello</p
|
225
|
+
tc "<p>Hello</p>\n<h1>Heading</h1>", "Hello\n= Heading =\n"
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'should parse linebreaks' do
|
229
229
|
# \\ (wiki-style) for line breaks.
|
230
|
-
tc "<p>This is the first line,<br/>and this is the second.</p
|
231
|
-
tc "<p>This is the first line,<br/>and this is the second.</p
|
232
|
-
tc "<p>This is the first line,<br/>and this is the second.</p
|
230
|
+
tc "<p>This is the first line,<br/>and this is the second.</p>\n", "This is the first line,\\\\and this is the second."
|
231
|
+
tc "<p>This is the first line,<br/>and this is the second.</p>\n", "This is the first line,[[br]]and this is the second."
|
232
|
+
tc "<p>This is the first line,<br/>and this is the second.</p>\n", "This is the first line,[[Br]]and this is the second."
|
233
233
|
end
|
234
234
|
|
235
235
|
it 'should parse blockquote' do
|
236
|
-
tc "<p><blockquote>Monty Python</blockquote></p
|
237
|
-
tc "<p><blockquote>Monty Python q2</blockquote></p
|
238
|
-
tc "<p><blockquote>Monty Python q2</blockquote></p
|
239
|
-
tc "<p><blockquote>Monty Python <strong>q2</strong></blockquote></p
|
240
|
-
tc "<p><blockquote>Monty Python<blockquote>q2</blockquote></blockquote></p
|
241
|
-
tc "<p><blockquote>Monty Python<blockquote>q2 q3</blockquote></blockquote></p
|
242
|
-
tc "<p><blockquote>Monty Python<blockquote><em>q2</em></blockquote>q1</blockquote></p
|
243
|
-
tc "<p><blockquote>Monty Python rules</blockquote></p
|
236
|
+
tc "<p><blockquote>Monty Python</blockquote></p>\n", "> Monty Python\n"
|
237
|
+
tc "<p><blockquote>Monty Python q2</blockquote></p>\n", "> Monty Python\n> q2\n"
|
238
|
+
tc "<p><blockquote>Monty Python q2</blockquote></p>\n", "> Monty Python\n>q2\n"
|
239
|
+
tc "<p><blockquote>Monty Python <strong>q2</strong></blockquote></p>\n", "> Monty Python\n>**q2**\n"
|
240
|
+
tc "<p><blockquote>Monty Python<blockquote>q2</blockquote></blockquote></p>\n", "> Monty Python\n> > q2\n"
|
241
|
+
tc "<p><blockquote>Monty Python<blockquote>q2 q3</blockquote></blockquote></p>\n", "> Monty Python\n> > q2\n>>q3\n"
|
242
|
+
tc "<p><blockquote>Monty Python<blockquote><em>q2</em></blockquote>q1</blockquote></p>\n", ">Monty Python\n> > ''q2''\n>q1"
|
243
|
+
tc "<p><blockquote>Monty Python rules</blockquote></p>\n", " Monty Python\n rules\n"
|
244
244
|
end
|
245
245
|
it 'should parse definition list' do
|
246
246
|
# FIXME: trailing space
|
@@ -260,7 +260,7 @@ describe TracWiki::Parser do
|
|
260
260
|
tc("<ul><li><strong>Item 1</strong></li></ul>", "* **Item 1")
|
261
261
|
|
262
262
|
# An item ends at blank line
|
263
|
-
tc("<ul><li>Item</li></ul><p>Par</p
|
263
|
+
tc("<ul><li>Item</li></ul><p>Par</p>\n", "* Item\n\nPar\n")
|
264
264
|
|
265
265
|
# An item ends at a heading
|
266
266
|
tc("<ul><li>Item</li></ul><h1>Heading</h1>", "* Item\n= Heading =\n")
|
@@ -298,7 +298,7 @@ describe TracWiki::Parser do
|
|
298
298
|
"1. Hello,\n World!\n * Not bold\n")
|
299
299
|
|
300
300
|
# [...] otherwise it will be treated as the beginning of bold text.
|
301
|
-
tc("<ul><li>Hello, World!</li></ul><p><strong>Not bold</strong></p
|
301
|
+
tc("<ul><li>Hello, World!</li></ul><p><strong>Not bold</strong></p>\n",
|
302
302
|
"* Hello,\nWorld!\n\n**Not bold\n")
|
303
303
|
end
|
304
304
|
|
@@ -316,7 +316,7 @@ describe TracWiki::Parser do
|
|
316
316
|
tc("<ol><li><strong>Item 1</strong></li></ol>", "1. **Item 1")
|
317
317
|
|
318
318
|
# An item ends at blank line
|
319
|
-
tc("<ol><li>Item</li></ol><p>Par</p
|
319
|
+
tc("<ol><li>Item</li></ol><p>Par</p>\n", "1. Item\n\nPar\n")
|
320
320
|
|
321
321
|
# An item ends at a heading
|
322
322
|
tc("<ol><li>Item</li></ol><h1>Heading</h1>", "1. Item\n= Heading =\n")
|
@@ -381,38 +381,38 @@ describe TracWiki::Parser do
|
|
381
381
|
|
382
382
|
it 'should parse ambiguious italics and url' do
|
383
383
|
# Uncommon URL schemes should not be parsed as URLs
|
384
|
-
tc("<p>This is what can go wrong:<em>this should be an italic text</em>.</p
|
384
|
+
tc("<p>This is what can go wrong:<em>this should be an italic text</em>.</p>\n",
|
385
385
|
"This is what can go wrong:''this should be an italic text''.")
|
386
386
|
|
387
387
|
# A link inside italic text
|
388
|
-
tc("<p>How about <em>a link, like <a href=\"http://example.org\">http://example.org</a>, in italic</em> text?</p
|
388
|
+
tc("<p>How about <em>a link, like <a href=\"http://example.org\">http://example.org</a>, in italic</em> text?</p>\n",
|
389
389
|
"How about ''a link, like http://example.org, in italic'' text?")
|
390
390
|
|
391
391
|
# Another test
|
392
|
-
tc("<p>Formatted fruits, for example:<em>apples</em>, oranges, <strong>pears</strong> ...</p
|
392
|
+
tc("<p>Formatted fruits, for example:<em>apples</em>, oranges, <strong>pears</strong> ...</p>\n",
|
393
393
|
"Formatted fruits, for example:''apples'', oranges, **pears** ...")
|
394
394
|
end
|
395
395
|
|
396
396
|
it 'should parse ambiguious bold and lists' do
|
397
|
-
tc "<p><strong> bold text </strong></p
|
398
|
-
tc "<p><blockquote><strong> bold text </strong></blockquote></p
|
397
|
+
tc "<p><strong> bold text </strong></p>\n", "** bold text **"
|
398
|
+
tc "<p><blockquote><strong> bold text </strong></blockquote></p>\n", " ** bold text **"
|
399
399
|
end
|
400
400
|
|
401
401
|
it 'should parse nowiki' do
|
402
402
|
# ... works as block
|
403
403
|
tc "<pre>Hello</pre>", "{{{\nHello\n}}}\n"
|
404
|
-
tc "<p><tt>{{{-}}}</tt></p
|
404
|
+
tc "<p><tt>{{{-}}}</tt></p>\n", "`{{{-}}}`\n"
|
405
405
|
|
406
406
|
# ... works inline
|
407
|
-
tc "<p>Hello <tt>world</tt>.</p
|
408
|
-
tc "<p><tt>Hello</tt> <tt>world</tt>.</p
|
407
|
+
tc "<p>Hello <tt>world</tt>.</p>\n", "Hello {{{world}}}."
|
408
|
+
tc "<p><tt>Hello</tt> <tt>world</tt>.</p>\n", "{{{Hello}}} {{{world}}}."
|
409
409
|
|
410
410
|
# No wiki markup is interpreted inbetween
|
411
411
|
tc "<pre>**Hello**</pre>", "{{{\n**Hello**\n}}}\n"
|
412
412
|
|
413
413
|
# Leading whitespaces are not permitted
|
414
|
-
# tc("<p>{{{ Hello }}}</p
|
415
|
-
tc("<p>{{{ Hello<blockquote>}}}</blockquote></p
|
414
|
+
# tc("<p>{{{ Hello }}}</p>\n", " {{{\nHello\n}}}")
|
415
|
+
tc("<p>{{{ Hello<blockquote>}}}</blockquote></p>\n", "{{{\nHello\n }}}")
|
416
416
|
|
417
417
|
# Assumed: Should preserve whitespace
|
418
418
|
tc("<pre> \t Hello, \t \n \t World \t </pre>",
|
@@ -422,38 +422,38 @@ describe TracWiki::Parser do
|
|
422
422
|
tc("<pre>nowikiblock\n}}}</pre>", "{{{\nnowikiblock\n }}}\n}}}\n")
|
423
423
|
|
424
424
|
# In inline nowiki, any trailing closing brace is included in the span
|
425
|
-
tc("<p>this is <tt>nowiki}</tt></p
|
426
|
-
tc("<p>this is <tt>nowiki}}</tt></p
|
427
|
-
tc("<p>this is <tt>nowiki}}}</tt></p
|
428
|
-
tc("<p>this is <tt>nowiki}}}}</tt></p
|
425
|
+
tc("<p>this is <tt>nowiki}</tt></p>\n", "this is {{{nowiki}}}}")
|
426
|
+
tc("<p>this is <tt>nowiki}}</tt></p>\n", "this is {{{nowiki}}}}}")
|
427
|
+
tc("<p>this is <tt>nowiki}}}</tt></p>\n", "this is {{{nowiki}}}}}}")
|
428
|
+
tc("<p>this is <tt>nowiki}}}}</tt></p>\n", "this is {{{nowiki}}}}}}}")
|
429
429
|
end
|
430
430
|
|
431
431
|
it 'should escape html' do
|
432
432
|
# Special HTML chars should be escaped
|
433
|
-
tc("<p><b>not bold</b></p
|
433
|
+
tc("<p><b>not bold</b></p>\n", "<b>not bold</b>")
|
434
434
|
|
435
435
|
# Image tags should be escape
|
436
|
-
tc("<p><img src='image.jpg'/></p
|
437
|
-
tc("<p><img src='image.jpg' alt='"tag"'/></p
|
436
|
+
tc("<p><img src='image.jpg'/></p>\n", "[[Image(image.jpg)]]")
|
437
|
+
tc("<p><img src='image.jpg' alt='"tag"'/></p>\n", "[[Image(image.jpg|\"tag\")]]")
|
438
438
|
|
439
439
|
# Malicious links should not be converted.
|
440
|
-
tc("<p><a href=\"javascript%3Aalert%28%22Boo%21%22%29\">Click</a></p
|
440
|
+
tc("<p><a href=\"javascript%3Aalert%28%22Boo%21%22%29\">Click</a></p>\n", "[[javascript:alert(\"Boo!\")|Click]]")
|
441
441
|
end
|
442
442
|
|
443
443
|
it 'should support character escape' do
|
444
|
-
tc "<p>** Not Bold **</p
|
445
|
-
tc "<p>// Not Italic //</p
|
446
|
-
tc "<p>* Not Bullet</p
|
444
|
+
tc "<p>** Not Bold **</p>\n", "!** Not Bold !**"
|
445
|
+
tc "<p>// Not Italic //</p>\n", "!// Not Italic !//"
|
446
|
+
tc "<p>* Not Bullet</p>\n", "!* Not Bullet"
|
447
447
|
# Following char is not a blank (space or line feed)
|
448
|
-
tc "<p>Hello ~ world</p
|
449
|
-
tc "<p>Hello ! world</p
|
450
|
-
tc "<p>Hello ! world</p
|
451
|
-
tc "<p>Hello ! world</p
|
448
|
+
tc "<p>Hello ~ world</p>\n", "Hello ~ world\n"
|
449
|
+
tc "<p>Hello ! world</p>\n", "Hello ! world\n"
|
450
|
+
tc "<p>Hello ! world</p>\n", "Hello ! world\n"
|
451
|
+
tc "<p>Hello ! world</p>\n", "Hello !\nworld\n"
|
452
452
|
# Not escaping inside URLs
|
453
|
-
tc "<p><a href=\"http://example.org/~user/\">http://example.org/~user/</a></p
|
453
|
+
tc "<p><a href=\"http://example.org/~user/\">http://example.org/~user/</a></p>\n", "http://example.org/~user/"
|
454
454
|
|
455
455
|
# Escaping links
|
456
|
-
tc "<p>http://www.example.org/</p
|
456
|
+
tc "<p>http://www.example.org/</p>\n", "~http://www.example.org/"
|
457
457
|
end
|
458
458
|
|
459
459
|
it 'should parse horizontal rule' do
|
@@ -467,12 +467,12 @@ describe TracWiki::Parser do
|
|
467
467
|
tc "<hr/>", " \t ---- \t "
|
468
468
|
|
469
469
|
# Nothing else than hyphens and whitespace is "allowed"
|
470
|
-
tc "<p>foo ----</p
|
471
|
-
tc "<p>---- foo</p
|
470
|
+
tc "<p>foo ----</p>\n", "foo ----\n"
|
471
|
+
tc "<p>---- foo</p>\n", "---- foo\n"
|
472
472
|
|
473
473
|
# [...] no whitespace is allowed between them
|
474
|
-
tc "<p>-- -- </p
|
475
|
-
tc "<p>-- -- </p
|
474
|
+
tc "<p>-- -- </p>\n", "-- -- "
|
475
|
+
tc "<p>-- -- </p>\n", "--\t-- "
|
476
476
|
end
|
477
477
|
|
478
478
|
it 'should parse table' do
|
@@ -517,8 +517,8 @@ describe TracWiki::Parser do
|
|
517
517
|
tc("<table><tr><td>table</td></tr></table><h1>heading</h1>", "||table||\n=heading=\n")
|
518
518
|
tc("<table><tr><td>table</td></tr></table><h1>heading</h1>", "||table||\n\n=heading=\n")
|
519
519
|
# table followed by paragraph
|
520
|
-
tc("<table><tr><td>table</td></tr></table><p>par</p
|
521
|
-
tc("<table><tr><td>table</td></tr></table><p>par</p
|
520
|
+
tc("<table><tr><td>table</td></tr></table><p>par</p>\n", "||table||\npar\n")
|
521
|
+
tc("<table><tr><td>table</td></tr></table><p>par</p>\n", "||table||\n\npar\n")
|
522
522
|
# table followed by unordered list
|
523
523
|
tc("<table><tr><td>table</td></tr></table><ul><li>item</li></ul>", "||table||\n* item\n")
|
524
524
|
tc("<table><tr><td>table</td></tr></table><ul><li>item</li></ul>", "||table||\n\n* item\n")
|
@@ -541,8 +541,8 @@ describe TracWiki::Parser do
|
|
541
541
|
tc("<h1>heading1</h1><h1>heading2</h1>", "=heading1=\n=heading2\n")
|
542
542
|
tc("<h1>heading1</h1><h1>heading2</h1>", "=heading1=\n\n=heading2\n")
|
543
543
|
# paragraph
|
544
|
-
tc("<h1>heading</h1><p>par</p
|
545
|
-
tc("<h1>heading</h1><p>par</p
|
544
|
+
tc("<h1>heading</h1><p>par</p>\n", "=heading=\npar\n")
|
545
|
+
tc("<h1>heading</h1><p>par</p>\n", "=heading=\n\npar\n")
|
546
546
|
# unordered list
|
547
547
|
tc("<h1>heading</h1><ul><li>item</li></ul>", "=heading=\n* item\n")
|
548
548
|
tc("<h1>heading</h1><ul><li>item</li></ul>", "=heading=\n\n* item\n")
|
@@ -562,26 +562,26 @@ describe TracWiki::Parser do
|
|
562
562
|
|
563
563
|
it 'should parse following paragraph' do
|
564
564
|
# heading
|
565
|
-
tc("<p>par</p
|
566
|
-
tc("<p>par</p
|
565
|
+
tc("<p>par</p>\n<h1>heading</h1>", "par\n=heading=")
|
566
|
+
tc("<p>par</p>\n<h1>heading</h1>", "par\n\n=heading=")
|
567
567
|
# paragraph
|
568
|
-
tc("<p>par par</p
|
569
|
-
tc("<p>par</p
|
568
|
+
tc("<p>par par</p>\n", "par\npar\n")
|
569
|
+
tc("<p>par</p>\n<p>par</p>\n", "par\n\npar\n")
|
570
570
|
# unordered
|
571
|
-
tc("<p>par</p
|
572
|
-
tc("<p>par</p
|
571
|
+
tc("<p>par</p>\n<ul><li>item</li></ul>", "par\n* item")
|
572
|
+
tc("<p>par</p>\n<ul><li>item</li></ul>", "par\n\n* item")
|
573
573
|
# ordered
|
574
|
-
tc("<p>par</p
|
575
|
-
tc("<p>par</p
|
574
|
+
tc("<p>par</p>\n<ol><li>item</li></ol>", "par\n1. item\n")
|
575
|
+
tc("<p>par</p>\n<ol><li>item</li></ol>", "par\n\n1. item\n")
|
576
576
|
# horizontal
|
577
|
-
tc("<p>par</p
|
578
|
-
tc("<p>par</p
|
577
|
+
tc("<p>par</p>\n<hr/>", "par\n----\n")
|
578
|
+
tc("<p>par</p>\n<hr/>", "par\n\n----\n")
|
579
579
|
# nowiki
|
580
|
-
tc("<p>par</p
|
581
|
-
tc("<p>par</p
|
580
|
+
tc("<p>par</p>\n<pre>nowiki</pre>", "par\n{{{\nnowiki\n}}}\n")
|
581
|
+
tc("<p>par</p>\n<pre>nowiki</pre>", "par\n\n{{{\nnowiki\n}}}\n")
|
582
582
|
# table
|
583
|
-
tc("<p>par</p
|
584
|
-
tc("<p>par</p
|
583
|
+
tc("<p>par</p>\n<table><tr><td>table</td></tr></table>", "par\n||table||\n")
|
584
|
+
tc("<p>par</p>\n<table><tr><td>table</td></tr></table>", "par\n\n||table||\n")
|
585
585
|
end
|
586
586
|
|
587
587
|
it 'should parse following unordered list' do
|
@@ -590,7 +590,7 @@ describe TracWiki::Parser do
|
|
590
590
|
tc("<ul><li>item</li></ul><h1>heading</h1>", "* item\n\n=heading=")
|
591
591
|
# paragraph
|
592
592
|
tc("<ul><li>item par</li></ul>", "* item\npar\n") # items may span multiple lines
|
593
|
-
tc("<ul><li>item</li></ul><p>par</p
|
593
|
+
tc("<ul><li>item</li></ul><p>par</p>\n", "* item\n\npar\n")
|
594
594
|
# unordered
|
595
595
|
tc("<ul><li>item</li><li>item</li></ul>", "* item\n* item\n")
|
596
596
|
tc("<ul><li>item</li></ul><ul><li>item</li></ul>", "* item\n\n* item\n")
|
@@ -614,7 +614,7 @@ describe TracWiki::Parser do
|
|
614
614
|
tc("<ol><li>item</li></ol><h1>heading</h1>", "1. item\n\n=heading=")
|
615
615
|
# paragraph
|
616
616
|
tc("<ol><li>item par</li></ol>", "1. item\npar\n") # items may span multiple lines
|
617
|
-
tc("<ol><li>item</li></ol><p>par</p
|
617
|
+
tc("<ol><li>item</li></ol><p>par</p>\n", "1. item\n\npar\n")
|
618
618
|
# unordered
|
619
619
|
tc("<ol><li>item</li></ol><ul><li>item</li></ul>", "1. item\n* item\n")
|
620
620
|
tc("<ol><li>item</li></ol><ul><li>item</li></ul>", "1. item\n\n* item\n")
|
@@ -637,8 +637,8 @@ describe TracWiki::Parser do
|
|
637
637
|
tc("<hr/><h1>heading</h1>", "----\n=heading=")
|
638
638
|
tc("<hr/><h1>heading</h1>", "----\n\n=heading=")
|
639
639
|
# paragraph
|
640
|
-
tc("<hr/><p>par</p
|
641
|
-
tc("<hr/><p>par</p
|
640
|
+
tc("<hr/><p>par</p>\n", "----\npar\n")
|
641
|
+
tc("<hr/><p>par</p>\n", "----\n\npar\n")
|
642
642
|
# unordered
|
643
643
|
tc("<hr/><ul><li>item</li></ul>", "----\n* item")
|
644
644
|
tc("<hr/><ul><li>item</li></ul>", "----\n* item")
|
@@ -664,8 +664,8 @@ describe TracWiki::Parser do
|
|
664
664
|
tc("<pre>nowiki</pre><h1>heading</h1>", "{{{\nnowiki\n}}}\n=heading=")
|
665
665
|
tc("<pre>nowiki</pre><h1>heading</h1>", "{{{\nnowiki\n}}}\n\n=heading=")
|
666
666
|
# paragraph
|
667
|
-
tc("<pre>nowiki</pre><p>par</p
|
668
|
-
tc("<pre>nowiki</pre><p>par</p
|
667
|
+
tc("<pre>nowiki</pre><p>par</p>\n", "{{{\nnowiki\n}}}\npar")
|
668
|
+
tc("<pre>nowiki</pre><p>par</p>\n", "{{{\nnowiki\n}}}\n\npar")
|
669
669
|
# unordered
|
670
670
|
tc("<pre>nowiki</pre><ul><li>item</li></ul>", "{{{\nnowiki\n}}}\n* item\n")
|
671
671
|
tc("<pre>nowiki</pre><ul><li>item</li></ul>", "{{{\nnowiki\n}}}\n\n* item\n")
|
@@ -684,38 +684,38 @@ describe TracWiki::Parser do
|
|
684
684
|
end
|
685
685
|
|
686
686
|
it 'should parse image' do
|
687
|
-
tc("<p><img src='image.jpg'/></p
|
688
|
-
tc("<p><img src='image.jpg' alt='tag'/></p
|
689
|
-
tc("<p><img src='http://example.org/image.jpg'/></p
|
687
|
+
tc("<p><img src='image.jpg'/></p>\n", "[[Image(image.jpg)]]")
|
688
|
+
tc("<p><img src='image.jpg' alt='tag'/></p>\n", "[[Image(image.jpg|tag)]]")
|
689
|
+
tc("<p><img src='http://example.org/image.jpg'/></p>\n", "[[Image(http://example.org/image.jpg)]]")
|
690
690
|
end
|
691
691
|
|
692
692
|
it 'should parse bold combo' do
|
693
|
-
tc("<p><strong>bold and</strong></p
|
693
|
+
tc("<p><strong>bold and</strong></p>\n<table><tr><td>table</td></tr></table><p>end<strong></strong></p>\n",
|
694
694
|
"**bold and\n||table||\nend**")
|
695
695
|
end
|
696
696
|
|
697
697
|
it 'should support extensions' do
|
698
|
-
tce("<p>This is <u>underlined</u></p
|
698
|
+
tce("<p>This is <u>underlined</u></p>\n",
|
699
699
|
"This is __underlined__")
|
700
700
|
|
701
|
-
tce("<p>This is <del>deleted</del></p
|
701
|
+
tce("<p>This is <del>deleted</del></p>\n",
|
702
702
|
"This is ~~deleted~~")
|
703
703
|
|
704
|
-
tce("<p>This is <sup>super</sup></p
|
704
|
+
tce("<p>This is <sup>super</sup></p>\n",
|
705
705
|
"This is ^super^")
|
706
706
|
|
707
|
-
tce("<p>This is <sub>sub</sub></p
|
707
|
+
tce("<p>This is <sub>sub</sub></p>\n",
|
708
708
|
"This is ,,sub,,")
|
709
709
|
|
710
|
-
tce("<p>®</p
|
711
|
-
tce("<p>®</p
|
712
|
-
tce("<p>©</p
|
713
|
-
tce("<p>©</p
|
710
|
+
tce("<p>®</p>\n", "(R)")
|
711
|
+
tce("<p>®</p>\n", "(r)")
|
712
|
+
tce("<p>©</p>\n", "(C)")
|
713
|
+
tce("<p>©</p>\n", "(c)")
|
714
714
|
end
|
715
715
|
|
716
716
|
it 'should support no_escape' do
|
717
|
-
tc("<p><a href=\"a%2Fb%2Fc\">a/b/c</a></p
|
718
|
-
tc("<p><a href=\"a/b/c\">a/b/c</a></p
|
717
|
+
tc("<p><a href=\"a%2Fb%2Fc\">a/b/c</a></p>\n", "[[a/b/c]]")
|
718
|
+
tc("<p><a href=\"a/b/c\">a/b/c</a></p>\n", "[[a/b/c]]", :no_escape => true)
|
719
719
|
end
|
720
720
|
end
|
721
721
|
# vim: tw=0
|