inline_test.go (view raw)
1//
2// Blackfriday Markdown Processor
3// Available at http://github.com/russross/blackfriday
4//
5// Copyright © 2011 Russ Ross <russ@russross.com>.
6// Distributed under the Simplified BSD License.
7// See README.md for details.
8//
9
10//
11// Unit tests for inline parsing
12//
13
14package blackfriday
15
16import (
17 "testing"
18)
19
20func runMarkdownInline(input string, extensions, htmlFlags int) string {
21 extensions |= EXTENSION_AUTOLINK
22 extensions |= EXTENSION_STRIKETHROUGH
23
24 htmlFlags |= HTML_USE_XHTML
25
26 renderer := HtmlRenderer(htmlFlags, "", "")
27
28 return string(Markdown([]byte(input), renderer, extensions))
29}
30
31func doTestsInline(t *testing.T, tests []string) {
32 doTestsInlineParam(t, tests, 0, 0)
33}
34
35func doSafeTestsInline(t *testing.T, tests []string) {
36 doTestsInlineParam(t, tests, 0, HTML_SAFELINK)
37}
38
39func doTestsInlineParam(t *testing.T, tests []string, extensions, htmlFlags int) {
40 // catch and report panics
41 var candidate string
42 /*
43 defer func() {
44 if err := recover(); err != nil {
45 t.Errorf("\npanic while processing [%#v] (%v)\n", candidate, err)
46 }
47 }()
48 */
49
50 for i := 0; i+1 < len(tests); i += 2 {
51 input := tests[i]
52 candidate = input
53 expected := tests[i+1]
54 actual := runMarkdownInline(candidate, extensions, htmlFlags)
55 if actual != expected {
56 t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]",
57 candidate, expected, actual)
58 }
59
60 // now test every substring to stress test bounds checking
61 if !testing.Short() {
62 for start := 0; start < len(input); start++ {
63 for end := start + 1; end <= len(input); end++ {
64 candidate = input[start:end]
65 _ = runMarkdownInline(candidate, extensions, htmlFlags)
66 }
67 }
68 }
69 }
70}
71
72func TestRawHtmlTag(t *testing.T) {
73 tests := []string{
74 "zz <style>p {}</style>\n",
75 "<p>zz p {}</p>\n",
76
77 "zz <STYLE>p {}</STYLE>\n",
78 "<p>zz p {}</p>\n",
79
80 "<SCRIPT>alert()</SCRIPT>\n",
81 "<p>alert()</p>\n",
82
83 "zz <SCRIPT>alert()</SCRIPT>\n",
84 "<p>zz alert()</p>\n",
85
86 "zz <script>alert()</script>\n",
87 "<p>zz alert()</p>\n",
88
89 " <script>alert()</script>\n",
90 "<p>alert()</p>\n",
91
92 "<script>alert()</script>\n",
93 "alert()\n",
94
95 "<script src='foo'></script>\n",
96 "\n",
97
98 "<script src='a>b'></script>\n",
99 "\n",
100
101 "zz <script src='foo'></script>\n",
102 "<p>zz </p>\n",
103
104 "zz <script src=foo></script>\n",
105 "<p>zz </p>\n",
106
107 `<script><script src="http://example.com/exploit.js"></SCRIPT></script>`,
108 "\n",
109
110 `'';!--"<XSS>=&{()}`,
111 "<p>'';!--"=&{()}</p>\n",
112
113 "<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>",
114 "<p></p>\n",
115
116 "<SCRIPT \nSRC=http://ha.ckers.org/xss.js></SCRIPT>",
117 "<p></p>\n",
118
119 `<IMG SRC="javascript:alert('XSS');">`,
120 "<p></p>\n",
121
122 "<IMG SRC=javascript:alert('XSS')>",
123 "<p></p>\n",
124
125 "<IMG SRC=JaVaScRiPt:alert('XSS')>",
126 "<p></p>\n",
127
128 "<IMG SRC=`javascript:alert(\"RSnake says, 'XSS'\")`>",
129 "<p></p>\n",
130
131 `<a onmouseover="alert(document.cookie)">xss link</a>`,
132 "<p>xss link</a></p>\n",
133
134 "<a onmouseover=alert(document.cookie)>xss link</a>",
135 "<p>xss link</a></p>\n",
136
137 // XXX: this doesn't pass yet
138 //`<IMG """><SCRIPT>alert("XSS")</SCRIPT>">`,
139 //"<p></p>\n",
140
141 "<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>",
142 "<p></p>\n",
143
144 `<IMG SRC=# onmouseover="alert('xxs')">`,
145 "<p></p>\n",
146
147 `<IMG SRC= onmouseover="alert('xxs')">`,
148 "<p></p>\n",
149
150 `<IMG onmouseover="alert('xxs')">`,
151 "<p></p>\n",
152
153 "<IMG SRC=javascript:alert('XSS')>",
154 "<p></p>\n",
155
156 "<IMG SRC=javascript:alert('XSS')>",
157 "<p></p>\n",
158
159 "<IMG SRC=javascript:alert('XSS')>",
160 "<p></p>\n",
161
162 `<IMG SRC="javascriptascript:alert('XSS');">`,
163 "<p></p>\n",
164
165 `<IMG SRC="jav	ascript:alert('XSS');">`,
166 "<p></p>\n",
167
168 `<IMG SRC="jav
ascript:alert('XSS');">`,
169 "<p></p>\n",
170
171 `<IMG SRC="jav
ascript:alert('XSS');">`,
172 "<p></p>\n",
173
174 `<IMG SRC="  javascript:alert('XSS');">`,
175 "<p></p>\n",
176
177 `<SCRIPT/XSS SRC="http://ha.ckers.org/xss.js"></SCRIPT>`,
178 "<p></p>\n",
179
180 // XXX: this doesn't pass yet
181 //"<BODY onload!#$%&()*~+-_.,:;?@[/|\\]^`=alert(\"XSS\")>",
182 //"\n",
183
184 `<SCRIPT/SRC="http://ha.ckers.org/xss.js"></SCRIPT>`,
185 "<p></p>\n",
186
187 // XXX: this doesn't pass yet
188 //`<<SCRIPT>alert("XSS");//<</SCRIPT>`,
189 //"",
190
191 "<SCRIPT SRC=http://ha.ckers.org/xss.js?< B >",
192 "<p></p>\n",
193
194 "<SCRIPT SRC=//ha.ckers.org/.j>",
195 "<p></p>\n",
196
197 // XXX: this doesn't pass yet
198 //`<IMG SRC="javascript:alert('XSS')"`,
199 //"",
200
201 // XXX: this doesn't pass yet
202 //"<iframe src=http://ha.ckers.org/scriptlet.html <",
203 //"",
204 }
205 doTestsInlineParam(t, tests, 0, HTML_SKIP_STYLE|HTML_SANITIZE_OUTPUT)
206}
207
208func TestEmphasis(t *testing.T) {
209 var tests = []string{
210 "nothing inline\n",
211 "<p>nothing inline</p>\n",
212
213 "simple *inline* test\n",
214 "<p>simple <em>inline</em> test</p>\n",
215
216 "*at the* beginning\n",
217 "<p><em>at the</em> beginning</p>\n",
218
219 "at the *end*\n",
220 "<p>at the <em>end</em></p>\n",
221
222 "*try two* in *one line*\n",
223 "<p><em>try two</em> in <em>one line</em></p>\n",
224
225 "over *two\nlines* test\n",
226 "<p>over <em>two\nlines</em> test</p>\n",
227
228 "odd *number of* markers* here\n",
229 "<p>odd <em>number of</em> markers* here</p>\n",
230
231 "odd *number\nof* markers* here\n",
232 "<p>odd <em>number\nof</em> markers* here</p>\n",
233
234 "simple _inline_ test\n",
235 "<p>simple <em>inline</em> test</p>\n",
236
237 "_at the_ beginning\n",
238 "<p><em>at the</em> beginning</p>\n",
239
240 "at the _end_\n",
241 "<p>at the <em>end</em></p>\n",
242
243 "_try two_ in _one line_\n",
244 "<p><em>try two</em> in <em>one line</em></p>\n",
245
246 "over _two\nlines_ test\n",
247 "<p>over <em>two\nlines</em> test</p>\n",
248
249 "odd _number of_ markers_ here\n",
250 "<p>odd <em>number of</em> markers_ here</p>\n",
251
252 "odd _number\nof_ markers_ here\n",
253 "<p>odd <em>number\nof</em> markers_ here</p>\n",
254
255 "mix of *markers_\n",
256 "<p>mix of *markers_</p>\n",
257 }
258 doTestsInline(t, tests)
259}
260
261func TestStrong(t *testing.T) {
262 var tests = []string{
263 "nothing inline\n",
264 "<p>nothing inline</p>\n",
265
266 "simple **inline** test\n",
267 "<p>simple <strong>inline</strong> test</p>\n",
268
269 "**at the** beginning\n",
270 "<p><strong>at the</strong> beginning</p>\n",
271
272 "at the **end**\n",
273 "<p>at the <strong>end</strong></p>\n",
274
275 "**try two** in **one line**\n",
276 "<p><strong>try two</strong> in <strong>one line</strong></p>\n",
277
278 "over **two\nlines** test\n",
279 "<p>over <strong>two\nlines</strong> test</p>\n",
280
281 "odd **number of** markers** here\n",
282 "<p>odd <strong>number of</strong> markers** here</p>\n",
283
284 "odd **number\nof** markers** here\n",
285 "<p>odd <strong>number\nof</strong> markers** here</p>\n",
286
287 "simple __inline__ test\n",
288 "<p>simple <strong>inline</strong> test</p>\n",
289
290 "__at the__ beginning\n",
291 "<p><strong>at the</strong> beginning</p>\n",
292
293 "at the __end__\n",
294 "<p>at the <strong>end</strong></p>\n",
295
296 "__try two__ in __one line__\n",
297 "<p><strong>try two</strong> in <strong>one line</strong></p>\n",
298
299 "over __two\nlines__ test\n",
300 "<p>over <strong>two\nlines</strong> test</p>\n",
301
302 "odd __number of__ markers__ here\n",
303 "<p>odd <strong>number of</strong> markers__ here</p>\n",
304
305 "odd __number\nof__ markers__ here\n",
306 "<p>odd <strong>number\nof</strong> markers__ here</p>\n",
307
308 "mix of **markers__\n",
309 "<p>mix of **markers__</p>\n",
310 }
311 doTestsInline(t, tests)
312}
313
314func TestEmphasisMix(t *testing.T) {
315 var tests = []string{
316 "***triple emphasis***\n",
317 "<p><strong><em>triple emphasis</em></strong></p>\n",
318
319 "***triple\nemphasis***\n",
320 "<p><strong><em>triple\nemphasis</em></strong></p>\n",
321
322 "___triple emphasis___\n",
323 "<p><strong><em>triple emphasis</em></strong></p>\n",
324
325 "***triple emphasis___\n",
326 "<p>***triple emphasis___</p>\n",
327
328 "*__triple emphasis__*\n",
329 "<p><em><strong>triple emphasis</strong></em></p>\n",
330
331 "__*triple emphasis*__\n",
332 "<p><strong><em>triple emphasis</em></strong></p>\n",
333
334 "**improper *nesting** is* bad\n",
335 "<p><strong>improper *nesting</strong> is* bad</p>\n",
336
337 "*improper **nesting* is** bad\n",
338 "<p><em>improper **nesting</em> is** bad</p>\n",
339 }
340 doTestsInline(t, tests)
341}
342
343func TestStrikeThrough(t *testing.T) {
344 var tests = []string{
345 "nothing inline\n",
346 "<p>nothing inline</p>\n",
347
348 "simple ~~inline~~ test\n",
349 "<p>simple <del>inline</del> test</p>\n",
350
351 "~~at the~~ beginning\n",
352 "<p><del>at the</del> beginning</p>\n",
353
354 "at the ~~end~~\n",
355 "<p>at the <del>end</del></p>\n",
356
357 "~~try two~~ in ~~one line~~\n",
358 "<p><del>try two</del> in <del>one line</del></p>\n",
359
360 "over ~~two\nlines~~ test\n",
361 "<p>over <del>two\nlines</del> test</p>\n",
362
363 "odd ~~number of~~ markers~~ here\n",
364 "<p>odd <del>number of</del> markers~~ here</p>\n",
365
366 "odd ~~number\nof~~ markers~~ here\n",
367 "<p>odd <del>number\nof</del> markers~~ here</p>\n",
368 }
369 doTestsInline(t, tests)
370}
371
372func TestCodeSpan(t *testing.T) {
373 var tests = []string{
374 "`source code`\n",
375 "<p><code>source code</code></p>\n",
376
377 "` source code with spaces `\n",
378 "<p><code>source code with spaces</code></p>\n",
379
380 "` source code with spaces `not here\n",
381 "<p><code>source code with spaces</code>not here</p>\n",
382
383 "a `single marker\n",
384 "<p>a `single marker</p>\n",
385
386 "a single multi-tick marker with ``` no text\n",
387 "<p>a single multi-tick marker with ``` no text</p>\n",
388
389 "markers with ` ` a space\n",
390 "<p>markers with a space</p>\n",
391
392 "`source code` and a `stray\n",
393 "<p><code>source code</code> and a `stray</p>\n",
394
395 "`source *with* _awkward characters_ in it`\n",
396 "<p><code>source *with* _awkward characters_ in it</code></p>\n",
397
398 "`split over\ntwo lines`\n",
399 "<p><code>split over\ntwo lines</code></p>\n",
400
401 "```multiple ticks``` for the marker\n",
402 "<p><code>multiple ticks</code> for the marker</p>\n",
403
404 "```multiple ticks `with` ticks inside```\n",
405 "<p><code>multiple ticks `with` ticks inside</code></p>\n",
406 }
407 doTestsInline(t, tests)
408}
409
410func TestLineBreak(t *testing.T) {
411 var tests = []string{
412 "this line \nhas a break\n",
413 "<p>this line<br />\nhas a break</p>\n",
414
415 "this line \ndoes not\n",
416 "<p>this line\ndoes not</p>\n",
417
418 "this has an \nextra space\n",
419 "<p>this has an<br />\nextra space</p>\n",
420 }
421 doTestsInline(t, tests)
422}
423
424func TestInlineLink(t *testing.T) {
425 var tests = []string{
426 "[foo](/bar/)\n",
427 "<p><a href=\"/bar/\">foo</a></p>\n",
428
429 "[foo with a title](/bar/ \"title\")\n",
430 "<p><a href=\"/bar/\" title=\"title\">foo with a title</a></p>\n",
431
432 "[foo with a title](/bar/\t\"title\")\n",
433 "<p><a href=\"/bar/\" title=\"title\">foo with a title</a></p>\n",
434
435 "[foo with a title](/bar/ \"title\" )\n",
436 "<p><a href=\"/bar/\" title=\"title\">foo with a title</a></p>\n",
437
438 "[foo with a title](/bar/ title with no quotes)\n",
439 "<p><a href=\"/bar/ title with no quotes\">foo with a title</a></p>\n",
440
441 "[foo]()\n",
442 "<p>[foo]()</p>\n",
443
444 "![foo](/bar/)\n",
445 "<p><img src=\"/bar/\" alt=\"foo\" />\n</p>\n",
446
447 "![foo with a title](/bar/ \"title\")\n",
448 "<p><img src=\"/bar/\" alt=\"foo with a title\" title=\"title\" />\n</p>\n",
449
450 "![foo with a title](/bar/\t\"title\")\n",
451 "<p><img src=\"/bar/\" alt=\"foo with a title\" title=\"title\" />\n</p>\n",
452
453 "![foo with a title](/bar/ \"title\" )\n",
454 "<p><img src=\"/bar/\" alt=\"foo with a title\" title=\"title\" />\n</p>\n",
455
456 "![foo with a title](/bar/ title with no quotes)\n",
457 "<p><img src=\"/bar/ title with no quotes\" alt=\"foo with a title\" />\n</p>\n",
458
459 "![foo]()\n",
460 "<p>![foo]()</p>\n",
461
462 "[a link]\t(/with_a_tab/)\n",
463 "<p><a href=\"/with_a_tab/\">a link</a></p>\n",
464
465 "[a link] (/with_spaces/)\n",
466 "<p><a href=\"/with_spaces/\">a link</a></p>\n",
467
468 "[text (with) [[nested] (brackets)]](/url/)\n",
469 "<p><a href=\"/url/\">text (with) [[nested] (brackets)]</a></p>\n",
470
471 "[text (with) [broken nested] (brackets)]](/url/)\n",
472 "<p>[text (with) <a href=\"brackets\">broken nested</a>]](/url/)</p>\n",
473
474 "[text\nwith a newline](/link/)\n",
475 "<p><a href=\"/link/\">text\nwith a newline</a></p>\n",
476
477 "[text in brackets] [followed](/by a link/)\n",
478 "<p>[text in brackets] <a href=\"/by a link/\">followed</a></p>\n",
479
480 "[link with\\] a closing bracket](/url/)\n",
481 "<p><a href=\"/url/\">link with] a closing bracket</a></p>\n",
482
483 "[link with\\[ an opening bracket](/url/)\n",
484 "<p><a href=\"/url/\">link with[ an opening bracket</a></p>\n",
485
486 "[link with\\) a closing paren](/url/)\n",
487 "<p><a href=\"/url/\">link with) a closing paren</a></p>\n",
488
489 "[link with\\( an opening paren](/url/)\n",
490 "<p><a href=\"/url/\">link with( an opening paren</a></p>\n",
491
492 "[link]( with whitespace)\n",
493 "<p><a href=\"with whitespace\">link</a></p>\n",
494
495 "[link]( with whitespace )\n",
496 "<p><a href=\"with whitespace\">link</a></p>\n",
497
498 "[![image](someimage)](with image)\n",
499 "<p><a href=\"with image\"><img src=\"someimage\" alt=\"image\" />\n</a></p>\n",
500
501 "[link](url \"one quote)\n",
502 "<p><a href=\"url "one quote\">link</a></p>\n",
503
504 "[link](url 'one quote)\n",
505 "<p><a href=\"url 'one quote\">link</a></p>\n",
506
507 "[link](<url>)\n",
508 "<p><a href=\"url\">link</a></p>\n",
509
510 "[link & ampersand](/url/)\n",
511 "<p><a href=\"/url/\">link & ampersand</a></p>\n",
512
513 "[link & ampersand](/url/)\n",
514 "<p><a href=\"/url/\">link & ampersand</a></p>\n",
515
516 "[link](/url/&query)\n",
517 "<p><a href=\"/url/&query\">link</a></p>\n",
518
519 "[[t]](/t)\n",
520 "<p><a href=\"/t\">[t]</a></p>\n",
521 }
522 doTestsInline(t, tests)
523}
524
525func TestSafeInlineLink(t *testing.T) {
526 var tests = []string{
527 "[foo](/bar/)\n",
528 "<p><a href=\"/bar/\">foo</a></p>\n",
529
530 "[foo](http://bar/)\n",
531 "<p><a href=\"http://bar/\">foo</a></p>\n",
532
533 "[foo](https://bar/)\n",
534 "<p><a href=\"https://bar/\">foo</a></p>\n",
535
536 "[foo](ftp://bar/)\n",
537 "<p><a href=\"ftp://bar/\">foo</a></p>\n",
538
539 "[foo](mailto://bar/)\n",
540 "<p><a href=\"mailto://bar/\">foo</a></p>\n",
541
542 // Not considered safe
543 "[foo](baz://bar/)\n",
544 "<p><tt>foo</tt></p>\n",
545 }
546 doSafeTestsInline(t, tests)
547}
548
549func TestReferenceLink(t *testing.T) {
550 var tests = []string{
551 "[link][ref]\n",
552 "<p>[link][ref]</p>\n",
553
554 "[link][ref]\n [ref]: /url/ \"title\"\n",
555 "<p><a href=\"/url/\" title=\"title\">link</a></p>\n",
556
557 "[link][ref]\n [ref]: /url/\n",
558 "<p><a href=\"/url/\">link</a></p>\n",
559
560 " [ref]: /url/\n",
561 "",
562
563 " [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n",
564 "",
565
566 " [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n [4spaces]: /url/\n",
567 "<pre><code>[4spaces]: /url/\n</code></pre>\n",
568
569 "[hmm](ref2)\n [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n",
570 "<p><a href=\"ref2\">hmm</a></p>\n",
571
572 "[ref]\n",
573 "<p>[ref]</p>\n",
574
575 "[ref]\n [ref]: /url/ \"title\"\n",
576 "<p><a href=\"/url/\" title=\"title\">ref</a></p>\n",
577 }
578 doTestsInline(t, tests)
579}
580
581func TestTags(t *testing.T) {
582 var tests = []string{
583 "a <span>tag</span>\n",
584 "<p>a <span>tag</span></p>\n",
585
586 "<span>tag</span>\n",
587 "<p><span>tag</span></p>\n",
588
589 "<span>mismatch</spandex>\n",
590 "<p><span>mismatch</spandex></p>\n",
591
592 "a <singleton /> tag\n",
593 "<p>a <singleton /> tag</p>\n",
594 }
595 doTestsInline(t, tests)
596}
597
598func TestAutoLink(t *testing.T) {
599 var tests = []string{
600 "http://foo.com/\n",
601 "<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
602
603 "1 http://foo.com/\n",
604 "<p>1 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
605
606 "1http://foo.com/\n",
607 "<p>1<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
608
609 "1.http://foo.com/\n",
610 "<p>1.<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
611
612 "1. http://foo.com/\n",
613 "<ol>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ol>\n",
614
615 "-http://foo.com/\n",
616 "<p>-<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
617
618 "- http://foo.com/\n",
619 "<ul>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ul>\n",
620
621 "_http://foo.com/\n",
622 "<p>_<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
623
624 "令狐http://foo.com/\n",
625 "<p>令狐<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
626
627 "令狐 http://foo.com/\n",
628 "<p>令狐 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
629
630 "ahttp://foo.com/\n",
631 "<p>ahttp://foo.com/</p>\n",
632
633 ">http://foo.com/\n",
634 "<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\n",
635
636 "> http://foo.com/\n",
637 "<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\n",
638
639 "go to <http://foo.com/>\n",
640 "<p>go to <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
641
642 "a secure <https://link.org>\n",
643 "<p>a secure <a href=\"https://link.org\">https://link.org</a></p>\n",
644
645 "an email <mailto:some@one.com>\n",
646 "<p>an email <a href=\"mailto:some@one.com\">some@one.com</a></p>\n",
647
648 "an email <mailto://some@one.com>\n",
649 "<p>an email <a href=\"mailto://some@one.com\">some@one.com</a></p>\n",
650
651 "an email <some@one.com>\n",
652 "<p>an email <a href=\"mailto:some@one.com\">some@one.com</a></p>\n",
653
654 "an ftp <ftp://old.com>\n",
655 "<p>an ftp <a href=\"ftp://old.com\">ftp://old.com</a></p>\n",
656
657 "an ftp <ftp:old.com>\n",
658 "<p>an ftp <a href=\"ftp:old.com\">ftp:old.com</a></p>\n",
659
660 "a link with <http://new.com?query=foo&bar>\n",
661 "<p>a link with <a href=\"http://new.com?query=foo&bar\">" +
662 "http://new.com?query=foo&bar</a></p>\n",
663
664 "quotes mean a tag <http://new.com?query=\"foo\"&bar>\n",
665 "<p>quotes mean a tag <http://new.com?query=\"foo\"&bar></p>\n",
666
667 "quotes mean a tag <http://new.com?query='foo'&bar>\n",
668 "<p>quotes mean a tag <http://new.com?query='foo'&bar></p>\n",
669
670 "unless escaped <http://new.com?query=\\\"foo\\\"&bar>\n",
671 "<p>unless escaped <a href=\"http://new.com?query="foo"&bar\">" +
672 "http://new.com?query="foo"&bar</a></p>\n",
673
674 "even a > can be escaped <http://new.com?q=\\>&etc>\n",
675 "<p>even a > can be escaped <a href=\"http://new.com?q=>&etc\">" +
676 "http://new.com?q=>&etc</a></p>\n",
677
678 "<a href=\"http://fancy.com\">http://fancy.com</a>\n",
679 "<p><a href=\"http://fancy.com\">http://fancy.com</a></p>\n",
680
681 "<a href=\"http://fancy.com\">This is a link</a>\n",
682 "<p><a href=\"http://fancy.com\">This is a link</a></p>\n",
683
684 "<a href=\"http://www.fancy.com/A_B.pdf\">http://www.fancy.com/A_B.pdf</a>\n",
685 "<p><a href=\"http://www.fancy.com/A_B.pdf\">http://www.fancy.com/A_B.pdf</a></p>\n",
686
687 "(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (\n",
688 "<p>(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (</p>\n",
689
690 "(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (part two: <a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a>)).\n",
691 "<p>(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (part two: <a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a>)).</p>\n",
692
693 "http://www.foo.com<br />\n",
694 "<p><a href=\"http://www.foo.com\">http://www.foo.com</a><br /></p>\n",
695 }
696 doTestsInline(t, tests)
697}
698
699func TestFootnotes(t *testing.T) {
700 tests := []string{
701 "testing footnotes.[^a]\n\n[^a]: This is the note\n",
702 `<p>testing footnotes.<sup class="footnote-ref" id="fnref:a"><a rel="footnote" href="#fn:a">1</a></sup></p>
703<div class="footnotes">
704
705<hr />
706
707<ol>
708<li id="fn:a">This is the note
709</li>
710</ol>
711</div>
712`,
713
714 `testing long[^b] notes.
715
716[^b]: Paragraph 1
717
718 Paragraph 2
719
720 ` + "```\n\tsome code\n\t```" + `
721
722 Paragraph 3
723
724No longer in the footnote
725`,
726 `<p>testing long<sup class="footnote-ref" id="fnref:b"><a rel="footnote" href="#fn:b">1</a></sup> notes.</p>
727
728<p>No longer in the footnote</p>
729<div class="footnotes">
730
731<hr />
732
733<ol>
734<li id="fn:b"><p>Paragraph 1</p>
735
736<p>Paragraph 2</p>
737
738<p><code>
739some code
740</code></p>
741
742<p>Paragraph 3</p>
743</li>
744</ol>
745</div>
746`,
747
748 `testing[^c] multiple[^d] notes.
749
750[^c]: this is [note] c
751
752
753omg
754
755[^d]: this is note d
756
757what happens here
758
759[note]: /link/c
760
761`,
762 `<p>testing<sup class="footnote-ref" id="fnref:c"><a rel="footnote" href="#fn:c">1</a></sup> multiple<sup class="footnote-ref" id="fnref:d"><a rel="footnote" href="#fn:d">2</a></sup> notes.</p>
763
764<p>omg</p>
765
766<p>what happens here</p>
767<div class="footnotes">
768
769<hr />
770
771<ol>
772<li id="fn:c">this is <a href="/link/c">note</a> c
773</li>
774<li id="fn:d">this is note d
775</li>
776</ol>
777</div>
778`,
779
780 "testing inline^[this is the note] notes.\n",
781 `<p>testing inline<sup class="footnote-ref" id="fnref:this-is-the-note"><a rel="footnote" href="#fn:this-is-the-note">1</a></sup> notes.</p>
782<div class="footnotes">
783
784<hr />
785
786<ol>
787<li id="fn:this-is-the-note">this is the note</li>
788</ol>
789</div>
790`,
791
792 "testing multiple[^1] types^[inline note] of notes[^2]\n\n[^2]: the second deferred note\n[^1]: the first deferred note\n\n\twhich happens to be a block\n",
793 `<p>testing multiple<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup> types<sup class="footnote-ref" id="fnref:inline-note"><a rel="footnote" href="#fn:inline-note">2</a></sup> of notes<sup class="footnote-ref" id="fnref:2"><a rel="footnote" href="#fn:2">3</a></sup></p>
794<div class="footnotes">
795
796<hr />
797
798<ol>
799<li id="fn:1"><p>the first deferred note</p>
800
801<p>which happens to be a block</p>
802</li>
803<li id="fn:inline-note">inline note</li>
804<li id="fn:2">the second deferred note
805</li>
806</ol>
807</div>
808`,
809
810 `This is a footnote[^1]^[and this is an inline footnote]
811
812[^1]: the footnote text.
813
814 may be multiple paragraphs.
815`,
816 `<p>This is a footnote<sup class="footnote-ref" id="fnref:1"><a rel="footnote" href="#fn:1">1</a></sup><sup class="footnote-ref" id="fnref:and-this-is-an-i"><a rel="footnote" href="#fn:and-this-is-an-i">2</a></sup></p>
817<div class="footnotes">
818
819<hr />
820
821<ol>
822<li id="fn:1"><p>the footnote text.</p>
823
824<p>may be multiple paragraphs.</p>
825</li>
826<li id="fn:and-this-is-an-i">and this is an inline footnote</li>
827</ol>
828</div>
829`,
830
831 "empty footnote[^]\n\n[^]: fn text",
832 "<p>empty footnote<sup class=\"footnote-ref\" id=\"fnref:\"><a rel=\"footnote\" href=\"#fn:\">1</a></sup></p>\n<div class=\"footnotes\">\n\n<hr />\n\n<ol>\n<li id=\"fn:\">fn text\n</li>\n</ol>\n</div>\n",
833 }
834
835 doTestsInlineParam(t, tests, EXTENSION_FOOTNOTES, 0)
836}