all repos — grayfriday @ c1e49967874c1bf3b4ecb804dee11dd73e50179a

blackfriday fork with a few changes

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>'';!--&quot;=&amp;{()}</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=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>",
154		"<p></p>\n",
155
156		"<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>",
157		"<p></p>\n",
158
159		"<IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>",
160		"<p></p>\n",
161
162		`<IMG SRC="javascriptascript:alert('XSS');">`,
163		"<p></p>\n",
164
165		`<IMG SRC="jav&#x09;ascript:alert('XSS');">`,
166		"<p></p>\n",
167
168		`<IMG SRC="jav&#x0A;ascript:alert('XSS');">`,
169		"<p></p>\n",
170
171		`<IMG SRC="jav&#x0D;ascript:alert('XSS');">`,
172		"<p></p>\n",
173
174		`<IMG SRC=" &#14;  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 &quot;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 &amp; ampersand</a></p>\n",
512
513		"[link &amp; ampersand](/url/)\n",
514		"<p><a href=\"/url/\">link &amp; ampersand</a></p>\n",
515
516		"[link](/url/&query)\n",
517		"<p><a href=\"/url/&amp;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 TestNofollowLink(t *testing.T) {
526	var tests = []string{
527		"[foo](/bar/)\n",
528		"<p><a href=\"/bar/\" rel=\"nofollow\">foo</a></p>\n",
529	}
530	doTestsInlineParam(t, tests, 0, HTML_SAFELINK|HTML_NOFOLLOW_LINKS)
531}
532
533func TestSafeInlineLink(t *testing.T) {
534	var tests = []string{
535		"[foo](/bar/)\n",
536		"<p><a href=\"/bar/\">foo</a></p>\n",
537
538		"[foo](http://bar/)\n",
539		"<p><a href=\"http://bar/\">foo</a></p>\n",
540
541		"[foo](https://bar/)\n",
542		"<p><a href=\"https://bar/\">foo</a></p>\n",
543
544		"[foo](ftp://bar/)\n",
545		"<p><a href=\"ftp://bar/\">foo</a></p>\n",
546
547		"[foo](mailto://bar/)\n",
548		"<p><a href=\"mailto://bar/\">foo</a></p>\n",
549
550		// Not considered safe
551		"[foo](baz://bar/)\n",
552		"<p><tt>foo</tt></p>\n",
553	}
554	doSafeTestsInline(t, tests)
555}
556
557func TestReferenceLink(t *testing.T) {
558	var tests = []string{
559		"[link][ref]\n",
560		"<p>[link][ref]</p>\n",
561
562		"[link][ref]\n   [ref]: /url/ \"title\"\n",
563		"<p><a href=\"/url/\" title=\"title\">link</a></p>\n",
564
565		"[link][ref]\n   [ref]: /url/\n",
566		"<p><a href=\"/url/\">link</a></p>\n",
567
568		"   [ref]: /url/\n",
569		"",
570
571		"   [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n",
572		"",
573
574		"   [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n    [4spaces]: /url/\n",
575		"<pre><code>[4spaces]: /url/\n</code></pre>\n",
576
577		"[hmm](ref2)\n   [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n",
578		"<p><a href=\"ref2\">hmm</a></p>\n",
579
580		"[ref]\n",
581		"<p>[ref]</p>\n",
582
583		"[ref]\n   [ref]: /url/ \"title\"\n",
584		"<p><a href=\"/url/\" title=\"title\">ref</a></p>\n",
585	}
586	doTestsInline(t, tests)
587}
588
589func TestTags(t *testing.T) {
590	var tests = []string{
591		"a <span>tag</span>\n",
592		"<p>a <span>tag</span></p>\n",
593
594		"<span>tag</span>\n",
595		"<p><span>tag</span></p>\n",
596
597		"<span>mismatch</spandex>\n",
598		"<p><span>mismatch</spandex></p>\n",
599
600		"a <singleton /> tag\n",
601		"<p>a <singleton /> tag</p>\n",
602	}
603	doTestsInline(t, tests)
604}
605
606func TestAutoLink(t *testing.T) {
607	var tests = []string{
608		"http://foo.com/\n",
609		"<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
610
611		"1 http://foo.com/\n",
612		"<p>1 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
613
614		"1http://foo.com/\n",
615		"<p>1<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
616
617		"1.http://foo.com/\n",
618		"<p>1.<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
619
620		"1. http://foo.com/\n",
621		"<ol>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ol>\n",
622
623		"-http://foo.com/\n",
624		"<p>-<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
625
626		"- http://foo.com/\n",
627		"<ul>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ul>\n",
628
629		"_http://foo.com/\n",
630		"<p>_<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
631
632		"令狐http://foo.com/\n",
633		"<p>令狐<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
634
635		"令狐 http://foo.com/\n",
636		"<p>令狐 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
637
638		"ahttp://foo.com/\n",
639		"<p>ahttp://foo.com/</p>\n",
640
641		">http://foo.com/\n",
642		"<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\n",
643
644		"> http://foo.com/\n",
645		"<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\n",
646
647		"go to <http://foo.com/>\n",
648		"<p>go to <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
649
650		"a secure <https://link.org>\n",
651		"<p>a secure <a href=\"https://link.org\">https://link.org</a></p>\n",
652
653		"an email <mailto:some@one.com>\n",
654		"<p>an email <a href=\"mailto:some@one.com\">some@one.com</a></p>\n",
655
656		"an email <mailto://some@one.com>\n",
657		"<p>an email <a href=\"mailto://some@one.com\">some@one.com</a></p>\n",
658
659		"an email <some@one.com>\n",
660		"<p>an email <a href=\"mailto:some@one.com\">some@one.com</a></p>\n",
661
662		"an ftp <ftp://old.com>\n",
663		"<p>an ftp <a href=\"ftp://old.com\">ftp://old.com</a></p>\n",
664
665		"an ftp <ftp:old.com>\n",
666		"<p>an ftp <a href=\"ftp:old.com\">ftp:old.com</a></p>\n",
667
668		"a link with <http://new.com?query=foo&bar>\n",
669		"<p>a link with <a href=\"http://new.com?query=foo&amp;bar\">" +
670			"http://new.com?query=foo&amp;bar</a></p>\n",
671
672		"quotes mean a tag <http://new.com?query=\"foo\"&bar>\n",
673		"<p>quotes mean a tag <http://new.com?query=\"foo\"&bar></p>\n",
674
675		"quotes mean a tag <http://new.com?query='foo'&bar>\n",
676		"<p>quotes mean a tag <http://new.com?query='foo'&bar></p>\n",
677
678		"unless escaped <http://new.com?query=\\\"foo\\\"&bar>\n",
679		"<p>unless escaped <a href=\"http://new.com?query=&quot;foo&quot;&amp;bar\">" +
680			"http://new.com?query=&quot;foo&quot;&amp;bar</a></p>\n",
681
682		"even a > can be escaped <http://new.com?q=\\>&etc>\n",
683		"<p>even a &gt; can be escaped <a href=\"http://new.com?q=&gt;&amp;etc\">" +
684			"http://new.com?q=&gt;&amp;etc</a></p>\n",
685
686		"<a href=\"http://fancy.com\">http://fancy.com</a>\n",
687		"<p><a href=\"http://fancy.com\">http://fancy.com</a></p>\n",
688
689		"<a href=\"http://fancy.com\">This is a link</a>\n",
690		"<p><a href=\"http://fancy.com\">This is a link</a></p>\n",
691
692		"<a href=\"http://www.fancy.com/A_B.pdf\">http://www.fancy.com/A_B.pdf</a>\n",
693		"<p><a href=\"http://www.fancy.com/A_B.pdf\">http://www.fancy.com/A_B.pdf</a></p>\n",
694
695		"(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (\n",
696		"<p>(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (</p>\n",
697
698		"(<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",
699		"<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",
700
701		"http://www.foo.com<br />\n",
702		"<p><a href=\"http://www.foo.com\">http://www.foo.com</a><br /></p>\n",
703
704		"http://foo.com/viewtopic.php?f=18&amp;t=297",
705		"<p><a href=\"http://foo.com/viewtopic.php?f=18&amp;t=297\">http://foo.com/viewtopic.php?f=18&amp;t=297</a></p>\n",
706
707		"http://foo.com/viewtopic.php?param=&quot;18&quot;zz",
708		"<p><a href=\"http://foo.com/viewtopic.php?param=&quot;18&quot;zz\">http://foo.com/viewtopic.php?param=&quot;18&quot;zz</a></p>\n",
709
710		"http://foo.com/viewtopic.php?param=&quot;18&quot;",
711		"<p><a href=\"http://foo.com/viewtopic.php?param=&quot;18&quot;\">http://foo.com/viewtopic.php?param=&quot;18&quot;</a></p>\n",
712	}
713	doTestsInline(t, tests)
714}
715
716func TestFootnotes(t *testing.T) {
717	tests := []string{
718		"testing footnotes.[^a]\n\n[^a]: This is the note\n",
719		`<p>testing footnotes.<sup class="footnote-ref" id="fnref:a"><a rel="footnote" href="#fn:a">1</a></sup></p>
720<div class="footnotes">
721
722<hr />
723
724<ol>
725<li id="fn:a">This is the note
726</li>
727</ol>
728</div>
729`,
730
731		`testing long[^b] notes.
732
733[^b]: Paragraph 1
734
735	Paragraph 2
736	
737	` + "```\n\tsome code\n\t```" + `
738	
739	Paragraph 3
740
741No longer in the footnote
742`,
743		`<p>testing long<sup class="footnote-ref" id="fnref:b"><a rel="footnote" href="#fn:b">1</a></sup> notes.</p>
744
745<p>No longer in the footnote</p>
746<div class="footnotes">
747
748<hr />
749
750<ol>
751<li id="fn:b"><p>Paragraph 1</p>
752
753<p>Paragraph 2</p>
754
755<p><code>
756some code
757</code></p>
758
759<p>Paragraph 3</p>
760</li>
761</ol>
762</div>
763`,
764
765		`testing[^c] multiple[^d] notes.
766
767[^c]: this is [note] c
768
769
770omg
771
772[^d]: this is note d
773
774what happens here
775
776[note]: /link/c
777
778`,
779		`<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>
780
781<p>omg</p>
782
783<p>what happens here</p>
784<div class="footnotes">
785
786<hr />
787
788<ol>
789<li id="fn:c">this is <a href="/link/c">note</a> c
790</li>
791<li id="fn:d">this is note d
792</li>
793</ol>
794</div>
795`,
796
797		"testing inline^[this is the note] notes.\n",
798		`<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>
799<div class="footnotes">
800
801<hr />
802
803<ol>
804<li id="fn:this-is-the-note">this is the note</li>
805</ol>
806</div>
807`,
808
809		"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",
810		`<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>
811<div class="footnotes">
812
813<hr />
814
815<ol>
816<li id="fn:1"><p>the first deferred note</p>
817
818<p>which happens to be a block</p>
819</li>
820<li id="fn:inline-note">inline note</li>
821<li id="fn:2">the second deferred note
822</li>
823</ol>
824</div>
825`,
826
827		`This is a footnote[^1]^[and this is an inline footnote]
828
829[^1]: the footnote text.
830
831    may be multiple paragraphs.
832`,
833		`<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>
834<div class="footnotes">
835
836<hr />
837
838<ol>
839<li id="fn:1"><p>the footnote text.</p>
840
841<p>may be multiple paragraphs.</p>
842</li>
843<li id="fn:and-this-is-an-i">and this is an inline footnote</li>
844</ol>
845</div>
846`,
847
848		"empty footnote[^]\n\n[^]: fn text",
849		"<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",
850	}
851
852	doTestsInlineParam(t, tests, EXTENSION_FOOTNOTES, 0)
853}