all repos — grayfriday @ c7617b05ad8da2825e1b2d311622bf3472101624

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