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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Creole v0.4 Live Preview</title>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" />
<style type="text/css">
.WikiText { display: block; width: 100%; height: 33%; }
table, td { border: solid 1px; }
tr { vertical-align: middle; text-align: center; }
div#UnitTest { position: absolute; right: 1em;
width: 15em; padding: 0; }
div#UnitTest h1 { font-size: large; text-align: center;
text-transform: uppercase; }
div#Main { padding: 0 1em 0 1em; margin: 0px;
position: absolute; top: 0px; left: 0px; right: 16em; }
table.unit-test { border: thin solid black; border-collapse: collapse; }
table.unit-test th { border: thin black; border-style: solid dashed; }
table.unit-test td { border: thin dashed black; }
table.unit-test strong { color: red; }
</style>
<script type="text/javascript">
// <![CDATA[
// Copyright (c) 2007 Chris Purcell.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
function $(element) {
if (document.getElementById)
return document.getElementById(element);
else if (document.all)
return document.all[element];
else
return null;
}
String.prototype.replaceEvalGl = function(regex, fn) {
var head = "";
var tail = "" + this;
while (m = tail.match(regex)) {
head += tail.substring(0,m.index) + fn(m);
tail = tail.substring(m.index + m[0].length);
}
return head + tail;
}
//// The markup rules ////////////////////////////////////////////////////////
MarkupRule = function(regex, rule) {
this.regex = regex;
this.rule = rule;
this.children = [ ];
}
MarkupRule.prototype.clone = function() {
var objectClone = new this.constructor();
for (var property in this)
objectClone[property] = this[property];
return objectClone;
}
MarkupRule.prototype.setChildren = function(children) {
this.children = children;
}
ElementRule = function(params) {
return new MarkupRule(params["regex"], function (r) {
var text = "";
if ("capture" in params)
text = r[params["capture"]];
if (text) {
if ("replaceRegex" in params)
text = text.replace(params["replaceRegex"], params["replaceString"]);
var tag = "<" + params["tag"] + ">";
var endtag = "</" + params["tag"] + ">";
if (!("tag" in params))
tag = endtag = "";
return tag + this.markUp(text) + endtag;
} else if ("tag" in params)
return "<" + params["tag"] + " />";
else
return "";
});
}
function toXHTML(wikiText) {
wikiText = wikiText.replace(/&/g, "&");
wikiText = wikiText.replace(/</g, "<");
wikiText = wikiText.replace(/>/g, ">");
wikiText = wikiText.replace(/"/g, """);
return toXHTML.root.markUp(wikiText);
}
// A header is text within equals signs (=)
toXHTML.h1 = new ElementRule({ tag: "h1", capture: 2,
regex: /(^|\n)[ \t]*={1}[ \t](.+?)[ \t]*=*\s*(\n|$)/ });
toXHTML.h2 = new ElementRule({ tag: "h2", capture: 2,
regex: /(^|\n)[ \t]*={2}[ \t](.+?)[ \t]*=*\s*(\n|$)/ });
toXHTML.h3 = new ElementRule({ tag: "h3", capture: 2,
regex: /(^|\n)[ \t]*={3}[ \t](.+?)[ \t]*=*\s*(\n|$)/ });
toXHTML.h4 = new ElementRule({ tag: "h4", capture: 2,
regex: /(^|\n)[ \t]*={4}[ \t](.+?)[ \t]*=*\s*(\n|$)/ });
toXHTML.h5 = new ElementRule({ tag: "h5", capture: 2,
regex: /(^|\n)[ \t]*={5}[ \t](.+?)[ \t]*=*\s*(\n|$)/ });
toXHTML.h6 = new ElementRule({ tag: "h6", capture: 2,
regex: /(^|\n)[ \t]*={6}[ \t](.+?)[ \t]*=*\s*(\n|$)/ });
// hr is a line of 4 dashes (-)
toXHTML.hr = new ElementRule({ tag: "hr", regex: /(^|\n)\s*----\s*(\n|$)/ });
// br is two backslashes (\)
toXHTML.br = new ElementRule({ tag: "br", regex: /\\\\/ });
// Preformatted blocks are wrapped in {{{...}}}
toXHTML.preBlock = new ElementRule({ tag: "pre", capture: 2,
regex: /(^|\n){{{\n?(.*?(\n.*?)*?)}}}(\n|$)/ });
// tt inlines are also wrapped in {{{...}}}
toXHTML.tt = new ElementRule({ tag: "tt",
regex: /{{{(.*?(?:\n.*?)*?)}}}/, capture: 1 });
// Unordered and ordered lists start with * or #
toXHTML.ulist = new ElementRule({ tag: "ul",
regex: /(^|\n)(\*[^*#].*(\n|$)([*#]{2}.*(\n|$))*)+/, capture: 0,
replaceRegex: /(^|\n)[*#]/g, replaceString: "$1" });
toXHTML.olist = new ElementRule({ tag: "ol",
regex: /(^|\n)(#[^*#].*(\n|$)([*#]{2}.*(\n|$))*)+/, capture: 0,
replaceRegex: /(^|\n)[*#]/g, replaceString: "$1" });
toXHTML.li = new ElementRule({tag:"li",regex:/.+(\n[*#].+)*/,capture:0});
// Tables
toXHTML.table = new ElementRule({ tag: "table",
regex: /(^|\n)(\|.*\|[ \t]*(\n|$))+/, capture: 0 });
toXHTML.tr = new ElementRule({ tag: "tr",
regex: /(^|\n)(\|.*)\|[ \t]*(\n|$)/, capture: 2 });
toXHTML.td = new ElementRule({ tag: "td",
regex: /[|]+([^|]*)/, capture: 1 });
// Kinds of text block:
// - paragraph is the fallback for the root rule
// and consists of blocks of text separated by blank lines
// - singleLine is used within lists
toXHTML.singleLine = new ElementRule({ regex: /.+/, capture: 0 });
toXHTML.paragraph = new ElementRule({ tag: "p",
regex: /(^|\n)([ \t]*[^\s].*(\n|$))+/, capture: 0 });
// Strongly emphasised text is surrounded by double-* characters
toXHTML.strong = new ElementRule({ tag: "strong", capture: 1,
regex:/\*\*([^*]*(?:\*[^*]+)*)\*\*/ });
// Emphasised text is surrounded by double-/ characters
// It must skip http:// or ftp:// internally
// (This would be a lot easier to write with negative lookbehind!)
toXHTML.em = new ElementRule({ tag: "em", capture: 1,
regex:"\\/\\/(" + // Starts with a double-/
"[^\\/hf]*(?:" +
"\\/?(?:http:\\/?|ftp:\\/?)*(?:" +
"h(?:t(?:tp?)?)?" + "|" +
"f(?:tp?)?" + "|" +
"(?:" +
"h[^t\\/hf]" + "|" +
"ht[^t\\/hf]" + "|" +
"htt[^p\\/hf]" + "|" +
"http[^:\\/hf]" + "|" +
"http:[^\\/hf]" + "|" +
"http:\\/[^\\/hf]" + "|" +
"http:\\/\\/" + "|" +
"f[^t\\/hf]" + "|" +
"ft[^p\\/hf]" + "|" +
"ftp[^:\\/hf]" + "|" +
"ftp:[^\\/hf]" + "|" +
"ftp:\\/[^\\/hf]" + "|" +
"ftp:\\/\\/" +
")" +
"[^\\/hf]*" +
")" + "|" +
"\\/[^\\/hf][^\\/hf]*" +
")*" +
")" +
"\\/\\/" // Ends with a double-/
});
// Links
toXHTML.linkPattern = "[^\\]|\\n]*(?:\\][^\\]|\\n]+)*";
toXHTML.urlProtocols = "(?:http|https|ftp|afs|news|nntp|mid|cid|mailto|" +
"wais|prospero|telnet|gopher)";
toXHTML.urlPattern = toXHTML.urlProtocols + ":" +
"[^\\]|\\n]*(?:\\][^\\]|\\n]+)*";
toXHTML.loneURLPattern = "(?:" + toXHTML.urlProtocols +
":[\\$-:=\\?-Z_a-z~]+[\\$-+\\/-Z_a-z~-])";
toXHTML.rawURL = new MarkupRule( "(" + toXHTML.loneURLPattern + ")",
function(r) {
return "<a href=\"" + r[1] + "\">" + r[1] + "</a>";
}
);
toXHTML.unnamedURL = new MarkupRule(
"\\[\\[(" + toXHTML.urlPattern + ")\\]\\]",
function(r) {
return "<a href=\"" + r[1] + "\">" + r[1] + "</a>";
}
);
toXHTML.unnamedLink = new MarkupRule(
"\\[\\[(" + toXHTML.linkPattern + ")\\]\\]",
function(r) {
return "<a href=\"" + r[1] + "\">" + r[1] + "</a>";
}
);
toXHTML.namedURL = new MarkupRule(
"\\[\\[(" + toXHTML.urlPattern + ")\\|(.*?)\\]\\]",
function(r) {
return "<a href=\"" + r[1] + "\">" + r[2] + "</a>";
}
);
toXHTML.namedLink = new MarkupRule(
"\\[\\[(" + toXHTML.linkPattern + ")\\|(.*?)\\]\\]",
function(r) {
return "<a href=\"" + r[1] + "\">" + r[2] + "</a>";
}
);
// Images
toXHTML.img = new MarkupRule(
"{{([^|\\n{}][^|\\n}]*(?:}[^|\\n}]+)*)\\|([^|\\n}]*(?:}[^|\\n}]+)*)}}",
function(r) {
return "<img src=\"" + r[1] + "\" alt=\"" + r[2] + "\"/>";
}
);
// Children of lists
toXHTML.ulist.children = toXHTML.olist.children = [ toXHTML.li ];
toXHTML.li.children = [ toXHTML.olist, toXHTML.ulist, toXHTML.singleLine ];
// Children of table items
toXHTML.table.children = [ toXHTML.tr ];
toXHTML.tr.children = [ toXHTML.td ];
toXHTML.td.children = [ toXHTML.singleLine ];
// Children within blocks
toXHTML.singleLine.children = toXHTML.paragraph.children =
toXHTML.strong.children = toXHTML.em.children = toXHTML.tt.children =
[ toXHTML.strong, toXHTML.em, toXHTML.br, toXHTML.rawURL,
toXHTML.unnamedURL, toXHTML.unnamedLink, toXHTML.namedURL,
toXHTML.namedLink, toXHTML.tt, toXHTML.img ];
// The root rule used to start the parser
toXHTML.root = new MarkupRule();
toXHTML.root.children = [ toXHTML.h1, toXHTML.h2, toXHTML.h3,
toXHTML.h4, toXHTML.h5, toXHTML.h6,
toXHTML.hr, toXHTML.olist,
toXHTML.ulist, toXHTML.preBlock,
toXHTML.table ];
toXHTML.root.fallback = new MarkupRule();
toXHTML.root.fallback.children = [ toXHTML.paragraph ];
//// Do the rendering ////////////////////////////////////////////////////////
// Apply each rule, and use whichever matches first in the text
// If there is a tie, use whichever is first in the list of rules
MarkupRule.prototype.markUp = function(text) {
var head = "";
var tail = "" + text;
var matches = [ ];
for (var i = 0; i < this.children.length; i++) {
matches[i] = tail.match(this.children[i].regex);
}
var best = false;
var b_i = false;
for (var i = 0; i < this.children.length; i++)
if (matches[i] && (!best || best.index > matches[i].index)) {
best = matches[i];
b_i = i;
}
while (best) {
if ((best.index > 0) && (this.fallback))
head += this.fallback.markUp(tail.substring(0,best.index));
else
head += tail.substring(0,best.index);
head += this.children[b_i].rule(best);
var chopped = best.index + best[0].length;
tail = tail.substring(chopped);
for (var i = 0; i < this.children.length; i++)
if (matches[i])
if (matches[i].index >= chopped)
matches[i].index -= chopped;
else
matches[i] = tail.match(this.children[i].regex);
best = false;
for (var i = 0; i < this.children.length; i++)
if (matches[i] && (!best || best.index > matches[i].index)) {
best = matches[i];
b_i = i;
}
}
if (tail.length > 0 && this.fallback)
tail = this.fallback.markUp(tail);
return head + tail;
}
//// Test the renderer ///////////////////////////////////////////////////////
toXHTML.UnitTest = function() {
var results = "<table class=\"unit-test\"><tr><th>Name</th><th>Status</th>"+
"</tr>";
for (var i = 0; i < toXHTML.UnitTest.tests.length; i++) {
var test = toXHTML.UnitTest.tests[i];
var input = test.input;
var expected = test.output;
var actual = toXHTML(input);
results += "<tr><td>" + test.name + "</td><td>";
if (expected == actual)
results += "Success";
else {
results += "<strong>Failure</strong>" + "</td><td>";
results += actual.replace(/&/g, "&").replace(/</g, "<").
replace(/\n/g, "\\n");
}
results += "</td></tr>";
}
results += "</table>";
return results;
}
toXHTML.UnitTest.tests = [
{
name: "Basic paragraph markup",
input: "Basic paragraph test with <, >, & and \"",
output: "<p>Basic paragraph test with <, >, & and "</p>"
},
{
name: "Simple unordered list",
input: "* list item\n*list item 2",
output: "<ul><li> list item</li>\n<li>list item 2</li></ul>"
},
{
name: "Simple ordered list",
input: "# list item\n#list item 2",
output: "<ol><li> list item</li>\n<li>list item 2</li></ol>"
},
{ // Test an ul item with a sublist
name: "Unordered item with unordered sublist",
input: "* Item\n** Subitem",
output: "<ul><li> Item<ul>\n<li> Subitem</li></ul></li></ul>"
},
{ // Test a sublist without an initial tag (should not make a list)
name: "Unordered sublist without initial tag",
input: "** Sublist item",
output: "<p>** Sublist item</p>"
},
{ // Test an ol item with a sublist
name: "Ordered item with ordered sublist",
input: "# Item\n## Subitem",
output: "<ol><li> Item<ol>\n<li> Subitem</li></ol></li></ol>"
},
{ // Test a sublist without an initial tag (should not make a list)
name: "Ordered sublist without initial tag",
input: "## Sublist item",
output: "<p>## Sublist item</p>"
},
{ // Test an unordered list with an ordered sublist
name: "Unordered item with ordered sublist",
input: "* Item\n*# Subitem",
output: "<ul><li> Item<ol>\n<li> Subitem</li></ol></li></ul>"
},
{ // Test hr
name: "Horizontal rule",
input: "Some text\n----\nSome more text",
output: "<p>Some text</p><hr /><p>Some more text</p>"
},
{ // Test pre block
name: "Preformatted block",
input: "{{{\nPreformatted block\n}}}",
output: "<pre>Preformatted block\n</pre>"
},
{ // Test two pre blocks
name: "Two preformatted blocks",
input: "{{{\nPreformatted block\n}}}\n{{{Block 2}}}",
output: "<pre>Preformatted block\n</pre><pre>Block 2</pre>"
},
{ // Test h1
name: "h1",
input: "= Header =",
output: "<h1>Header</h1>"
},
{ // Test h2
name: "h2",
input: "== Header =",
output: "<h2>Header</h2>"
},
{ // Test h3
name: "h3",
input: "=== Header =",
output: "<h3>Header</h3>"
},
{ // Test h4
name: "h4",
input: "==== Header =",
output: "<h4>Header</h4>"
},
{ // Test h5
name: "h5",
input: "===== Header",
output: "<h5>Header</h5>"
},
{ // Test h6
name: "h6",
input: "====== Header =",
output: "<h6>Header</h6>"
},
{ // Test above h6 (should be ignored)
name: ">h6",
input: "======= Header =",
output: "<p>======= Header =</p>"
},
{ // Test tables
name: "Tables",
input: "| A | B |\n| //C// | **D** \\\\ E |",
output: "<table><tr><td> A </td><td> B </td></tr>" +
"<tr><td> <em>C</em> </td>" +
"<td> <strong>D</strong> <br /> E </td></tr></table>"
},
{ // Test raw URL
name: "Raw URL",
input: "http://example.com/examplepage",
output: "<p><a href=\"http://example.com/examplepage\">" +
"http://example.com/examplepage</a></p>"
},
{ // Test unnamed URL
name: "Unnamed URL",
input: "[[http://example.com/examplepage]]",
output: "<p><a href=\"http://example.com/examplepage\">" +
"http://example.com/examplepage</a></p>"
},
{ // Test named URL
name: "Named URL",
input: "[[http://example.com/examplepage|Example Page]]",
output: "<p>" +
"<a href=\"http://example.com/examplepage\">Example Page</a></p>"
},
{ // Test unnamed link
name: "Unnamed link",
input: "[[MyPage]]",
output: "<p><a href=\"MyPage\">MyPage</a></p>"
},
{ // Test named link
name: "Named link",
input: "[[MyPage|My page]]",
output: "<p><a href=\"MyPage\">My page</a></p>"
},
{ // Test images
name: "Image",
input: "{{image.gif|my image}}",
output: "<p><img src=\"image.gif\" alt=\"my image\"/></p>"
},
{ // Test inline tt
name: "Inline tt",
input: "Inline {{{tt}}} example {{{here}}}!",
output: "<p>Inline <tt>tt</tt> example <tt>here</tt>!</p>"
},
{ // Test **strong**
name: "Strong",
input: "**Strong**",
output: "<p><strong>Strong</strong></p>"
},
{ // Test //emphasis//
name: "Emphasis",
input: "//Emphasis//",
output: "<p><em>Emphasis</em></p>"
},
//// WikiCreole tests
{ // Tests multi-line emphasis behaviour
name: "Multi-line emphasis",
input: "Bold and italics should //be\nable// to cross lines.\n\n" +
"But, should //not be...\n\n...able// to cross paragraphs.",
output: "<p>Bold and italics should <em>be\nable</em> to cross lines." +
"\n</p>" + "<p>\nBut, should //not be...\n</p>" +
"<p>\n...able// to cross paragraphs.</p>"
},
{ // Tests URL/emphasis ambiguity handling
name: "URL/emphasis ambiguity",
input: "This is an //italic// text. This is a url: " +
"http://www.wikicreole.org. This is what can go wrong://this " +
"should be an italic text//.",
output: "<p>This is an <em>italic</em> text. This is a url: " +
"<a href=\"http://www.wikicreole.org\">" +
"http://www.wikicreole.org</a>. This is what can go wrong:" +
"<em>this should be an italic text</em>.</p>"
},
//// Awkward emphasis edge cases
{
name: "Difficult emphasis #1",
input: "// http://www.link.org //",
output: "<p><em> <a href=\"http://www.link.org\">" +
"http://www.link.org</a> </em></p>"
},
{
name: "Difficult emphasis #2",
input: "// http //",
output: "<p><em> http </em></p>"
},
{
name: "Difficult emphasis #3",
input: "// httphpthtpht //",
output: "<p><em> httphpthtpht </em></p>"
},
{
name: "Difficult emphasis #4",
input: "// http: //",
output: "<p><em> http: </em></p>"
},
{
name: "Difficult emphasis #5",
input: "// http://",
output: "<p>// <a href=\"http://\">http://</a></p>"
},
{
name: "Difficult emphasis #6",
input: "// http:////",
output: "<p><em> <a href=\"http://\">http://</a></em></p>"
},
{
name: "Difficult emphasis #7",
input: "//httphpthtphtt//",
output: "<p><em>httphpthtphtt</em></p>"
},
{
name: "Difficult emphasis #8",
input: "//http://link.org//",
output: "<p><em><a href=\"http://link.org\">" +
"http://link.org</a></em></p>"
},
{
name: "Difficult emphasis #9",
input: "// ftp://www.link.org //",
output: "<p><em> <a href=\"ftp://www.link.org\">" +
"ftp://www.link.org</a> </em></p>"
},
{
name: "Difficult emphasis #10",
input: "// ftp //",
output: "<p><em> ftp </em></p>"
},
{
name: "Difficult emphasis #11",
input: "// fttpfptftpft //",
output: "<p><em> fttpfptftpft </em></p>"
},
{
name: "Difficult emphasis #12",
input: "// ftp: //",
output: "<p><em> ftp: </em></p>"
},
{
name: "Difficult emphasis #13",
input: "// ftp://",
output: "<p>// <a href=\"ftp://\">ftp://</a></p>"
},
{
name: "Difficult emphasis #14",
input: "// ftp:////",
output: "<p><em> <a href=\"ftp://\">ftp://</a></em></p>"
},
{
name: "Difficult emphasis #15",
input: "//fttpfptftpftt//",
output: "<p><em>fttpfptftpftt</em></p>"
},
{
name: "Difficult emphasis #16",
input: "//ftp://link.org//",
output: "<p><em><a href=\"ftp://link.org\">" +
"ftp://link.org</a></em></p>"
}
];
//// Install the renderer //////////////////////////////////////////////
function updateRender() {
$("Html").innerHTML = toXHTML($("Text").value);
}
function installRenderer() {
element = $("Text");
element.onkeyup = element.onkeypress = element.ondrop =
element.onchange = updateRender;
updateRender();
$("UnitTest").innerHTML = "<h1>Unit Testing</h1>" +
toXHTML.UnitTest();
}
window.onload = installRenderer;
// ]]>
</script>
</head>
<body>
<div id="Main">
<form action="">
<p><textarea name="Text" id="Text" class="WikiText" rows="20" cols="50">
= Creole
{{http://www.wikicreole.org/attach/LeftMenu/viki.png|Creole}}\\
Creole is a common wiki markup language intended to be used across many different wikis. Its aim is not to replace existing markup, but instead to enable wiki users to transfer basic content seamlessly across wikis, and lower the barrier to entry for novice users.
= Regular Language–Recursive Descent Parser
This text has been formatted using a //regular language–recursive descent// (RLRD) parser design. That is, rules are applied in a recursive descent that matches the ultimate XML output; at each level of the descent, a set of regular expressions define the text that each child rule can "consume". Rules are applied greedily (i.e. earliest-match first). Unlike standard markup designs, this makes edge-cases between rules explicit, and allows a parser to be certified XHTML-compliant.
The parser is written in Javascript, allowing greater flexibility in the deployment of the parser. The underlying RLRD design can be implemented in any language.
= Live Preview
This document demonstrates a live Javascript preview, using this RLRD renderer. Editing the above text area will change this text.
The markup follows the basic rules of [[http://www.wikicreole.org/wiki/Creole0.4|Creole v0.4]].</textarea></p>
</form>
<div id="Html" class="RenderedText">Javascript disabled</div>
</div>
<div id="UnitTest"></div>
</body>
</html>
|