/
TextileSpec.scala
523 lines (376 loc) · 10.7 KB
/
TextileSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/*
* Copyright 2008-2011 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.liftweb
package textile
import xml._
import org.specs.Specification
import common._
import util._
object TextileSpec extends Specification {
val shouldRelax = (java.lang.Boolean.getBoolean("textile.relax"))
import TextileParser._
"A Textile Parser" can {
"deal with italic" in {
toHtml("foo __bar__") must ==/(<p>foo <i>bar</i></p> )
}
"deal with multi-line div" in {
val div =
"""<div class="vcard">
<div class="fn">Joe Doe</div>
<div class="org">The Example Company</div>
<div class="tel">604-555-1234</div>
http://example.com/
</div>"""
val res = toHtml(div)
res must ==/(<p><div>
<div>Joe Doe</div>
<div>The Example Company</div>
<div>604-555-1234</div>
<a href="http://example.com/">http://example.com/</a>
</div></p>)
}
"deal with bold and italic foo dog" in {
toHtml("*foo* dog __bar__") must ==/(<p><strong>foo</strong> dog <i>bar</i></p> )
}
"deal with bold and italic" in {
toHtml("*foo* __bar__") must ==/(<p><strong>foo</strong> <i>bar</i></p> )
}
"attributes in link quotes" in {
val res = toHtml(""""(cms-woof) click here":# """)
res must ==/(<p><a href="javascript://" class="cms-woof"> click here</a> </p>)
}
"Be a single line of text" in {
toHtml("Hello World") must ==/(<p>Hello World</p>)
}
"Make things bold" in {
toHtml("**Hello World**") must ==/(<p><b>Hello World</b></p>)
}
"End line elements with punctuation" in {
toHtml("And then? She *fell*!") must ==/(<p>And then? She <strong>fell</strong>!</p>)
}
"Start line elements with punctuation" in {
toHtml("see:_Hello word_") must ==/(<p>see:<em>Hello word</em></p>)
}
"**Bold * Not Strong**" in {
toHtml("**Bold * Not Strong**") must ==/(<p><b>Bold * Not Strong</b></p>)
}
"Make other things bold" in {
toHtml("Dude this is **Hello World** kind of stuff") must ==/(<p>Dude this is <b>Hello World</b> kind of stuff</p>)
}
"I am <i>Italic</i> <u>under</u> <strong>strong</strong>" in {
toHtml("I am <i>Italic</i> <u>under</u> <strong>strong</strong>") must ==/(<p>I am <i>Italic</i> <u>under</u> <strong>strong</strong></p>)
}
"I am <em>very</em> serious" in {
toHtml("I am <em>very</em> serious") must ==/(<p>I am <em>very</em> serious</p>)
}
"Observe -- very nice!" in {
toHtml("Observe -- very nice!") must ==/(<p>Observe \u2014 very nice!</p>)
}
"Observe - tiny and brief." in {
toHtml("Observe - tiny and brief.") must ==/(<p>Observe \u2013 tiny and brief.</p>)
}
"\"Observe!\"" in {
val ret = toHtml("\"Observe!\"")
ret must ==/(<p>\u201cObserve!\u201d</p>)
}
"A simple example." in {
toHtml("A simple example.") must ==/(<p>A simple example.</p>)
}
"Multi-line with - signs" in {
val res = toHtml(
"""
A simple example.
A hi-tech example.
A hi-tech lo-tech example.
A -deleted- example.
A -deleted hi-tech- example.
A regular example.
""")
res must ==/(<p>A simple example.<br />
A hi-tech example. <br />
A hi-tech lo-tech example. <br />
A <del>deleted</del> example.<br />
A <del>deleted hi-tech</del> example. <br />
A regular example.</p>)
}
"A question mark in an URL" in {
val res = toHtml(""""video link":http://www.youtube.com/watch?v=FclcMfzjwug foo""")
res must ==/(<p><a href="http://www.youtube.com/watch?v=FclcMfzjwug">video link</a> foo</p>)
}
"a link http://yahoo.com inside" in {
toHtml("a link http://yahoo.com inside") must ==/(<p>a link <a href="http://yahoo.com">http://yahoo.com</a> inside</p>)
}
"a quoted link" in {
toHtml("""I searched "Google":http://google.com.""") must ==/(<p>I searched <a href="http://google.com.">Google</a></p>)
}
"deal with a very long line of text" in {
val sb = new StringBuilder()
(1 to 10000).foreach(i => sb.append(i.toString+" "))
toHtml(sb.toString)
}
"h3" in {
toHtml("h3. Dogs eat dogfood") must ==/(<h3>Dogs eat dogfood</h3>)
}
"h3 with whitespace" in {
toHtml(" h3. Dogs eat dogfood") must ==/(<h3>Dogs eat dogfood</h3>)
}
"Single line delete " in {
toHtml("This contains -deleted stuff-") must ==/(<p>This contains <del>deleted stuff</del></p>)
}
"3 bullets" in {
val it = toHtml(
"""
* Hello
* Dude
* Dog
""")
it must ==/(
<ul><li> Hello</li>
<li> Dude</li>
<li> Dog</li>
</ul>
)
}
"3 bullets strong" in {
val it = toHtml(
"""
* *Hello* moo
* Dude
* Dog
""")
it must ==/(
<ul><li> <strong>Hello</strong> moo</li>
<li> Dude</li>
<li> Dog</li>
</ul>
)
}
"3 bullets not strong" in {
val it = toHtml(
"""
* *Hello moo
* Dude
* Dog
""")
it must ==/(
<ul><li> *Hello moo</li>
<li> Dude</li>
<li> Dog</li>
</ul>
)
}
"3 bullets after a line" in {
val it = toHtml(
"""
I Like Yaks
* Hello moo
* Dude
* Dog
""")
it must ==/(
<p>I Like Yaks<br/><ul><li> Hello moo</li>
<li> Dude</li>
<li> Dog</li>
</ul>
</p>
)
}
"a link http://yahoo.com not inside" in {
toHtml("a link http://yahoo.com not inside", true).toString.trim must_== "<p>a link http://yahoo.com not inside</p>"
}
}
"Fast" in {
val s = """VF-DE:
IFC.ksh: 04/10/08 03:26:52: *************** start of IFC.ksh ***************
IFC.ksh: 04/10/08 15:34:30: *************** end of IFC.ksh ***************
VF-ES:
IFC.ksh: 04/11/08 03:11:48: *************** start of IFC.ksh ***************
IFC.ksh: 04/11/08 04:48:24: *************** end of IFC.ksh ***************
VF-GR:
IFC.ksh: 04/11/08 03:11:59: *************** start of IFC.ksh ***************
IFC.ksh: 04/11/08 03:46:47: *************** end of IFC.ksh ***************
VF-IE:
IFC.ksh: 04/11/08 03:15:07: *************** start of IFC.ksh ***************
IFC.ksh: 04/11/08 05:36:57: *************** end of IFC.ksh ***************
VF-IT:
IFC.ksh: 04/11/08 03:05:07: *************** start of IFC.ksh ***************
IFC.ksh: 04/11/08 05:06:09: *************** end of IFC.ksh ***************
VF-NL:
IFC.ksh: 04/11/08 03:55:05: *************** start of IFC.ksh ***************
IFC.ksh: 04/11/08 04:28:57: *************** end of IFC.ksh ***************
VF-PT:
IFC.ksh: 04/11/08 03:00:09: *************** start of IFC.ksh ***************
IFC.ksh: 04/11/08 03:32:05: *************** end of IFC.ksh ***************
VF-UK:
IFC.ksh: 04/11/08 03:38:41: *************** start of IFC.ksh ***************
IFC.ksh: 04/11/08 05:26:49: *************** end of IFC.ksh ***************
I saved the entry by pressing "Yep" button, but because the symbol "-" caused the subsequent letters to be crossed out I've edited the text like this:
DE:
IFC.ksh: 04/10/08 03:26:52: *************** start of """
val (time, res) = Helpers.calcTime{
toHtml(s)
}
val cmp: Long = (if (shouldRelax) 10000L else 3000L)
time must be_<( cmp)
}
"Fast 2" in {
val s = """I am <em>very</em> serious
Observe -- very nice!
Observe - tiny and brief.
"Observe!"
Hello Dude
**Bold * Not Strong**
my bold line **bold**
**strong* Not Bold
*strong*
This is a single paragraph
This is another paragraph
I am <b>very</b> serious.
This
is a paragraph
<pre>
I am <b>very</b> serious.
Oh, yes I am!!
</pre>
I spoke.
And none replied.
Observe...
Observe: 2 x 2.
one(TM), two(R), three(C).
h1. Header 1
second line of header 1
h2. Header 2
h3. Header 3
An old text
bq. A block quotation.
Any old text
This is covered elsewhere[1].
fn1. Down here, in fact.
I _believe_ every word.
And then? She *fell*!
I __know__.
I **really** __know__.
??Cat's Cradle?? by Vonnegut
Convert with @r.to_html@
I'm -sure- not sure.
You are a +pleasant+ child.
a ^2^ + b ^2^ = c ^2^
log ~2~ x
I'm %unaware% of most soft drinks.
I'm %{color:red}unaware%
of most soft drinks.
http://hobix.com/textile/#attributes
I searched "Google":http://google.com.
CamelCase
\\CamelCase
ThreeHumpCamel
Four4FourHumpCamel
I am crazy about "Hobix":hobix
and "it's":hobix "all":hobix I ever
"link to":hobix!
[hobix]http://hobix.com
# A first item
# A second item
# A third
# Fuel could be:
## Coal
## Gasoline
## Electricity
# Humans need only:
## Water
## Protein
* A first item
* A second item
* A third
* Fuel could be:
** Coal
** Gasoline
** Electricity
* Humans need only:
** Water
** Protein
| name | age | sex |
| joan | 24 | f |
| archie | 29 | m |
| bella | 45 | f |
|_. name |_. age |_. sex |
| joan | 24 | f |
| archie | 29 | m |
| bella | 45 | f |
|_. attribute list |
|<. align left |
|>. align right|
|=. center |
|<>. justify this block |
|^. valign top |
|~. bottom |
|\2. spans two cols |
| col 1 | col 2 |
|/3. spans 3 rows | a |
| b |
| c |
|{background:#ddd}. Grey cell|
table{border:1px solid black}.
|This|is|a|row|
|This|is|a|row|
|This|is|a|row|
{background:#ddd}. |This|is|grey|row|
p<. align left
p>. align right
p=. centered
p<>. justified
p(. left ident 1em
p((. left ident 2em
p))). right ident 3em
h2()>. Bingo.
h3()>[no]{color:red}. Bingo
<pre>
<code>
a.gsub!( /</, '' )
</code>
</pre>
<div style='float:right;'>
float right
</div>
<div style='float:right;'>
h3. Sidebar
"Hobix":http://hobix.com/
"Ruby":http://ruby-lang.org/
</div>
The main text of the
page goes here and will
stay to the left of the
sidebar.
!http://hobix.com/sample.jpg!
!http://hobix.com/sa.jpg(Bunny.)!
!http://hobix.com/sample.jpg!:http://hobix.com/
!>http://hobix.com/sample.jpg!
And others sat all round the small
machine and paid it to sing to them.
We use CSS(Cascading Style Sheets).
"""
val (time, res) = Helpers.calcTime{
toHtml(s)
}
time must be_< (if (shouldRelax) 10000L else 3000L)
}
"""Hello:
* THis is a * on a line
* This is a *strong* line
* This is a **Bold** line
* This is a line with no markup
"""
}