all repos — grayfriday @ cf6bfc9d6d9f0d0279ff7660e0095b21b7df8c86

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		"[foo](/bar/)\n",
430		"<p><a href=\"/bar/\">foo</a></p>\n",
431	}
432	doTestsInlineParam(t, tests, 0, HTML_SAFELINK|HTML_NOFOLLOW_LINKS,
433		HtmlRendererParameters{})
434}
435
436func TestHrefTargetBlank(t *testing.T) {
437	var tests = []string{
438		// internal link
439		"[foo](/bar/)\n",
440		"<p><a href=\"/bar/\">foo</a></p>\n",
441
442		"[foo](http://example.com)\n",
443		"<p><a href=\"http://example.com\" target=\"_blank\">foo</a></p>\n",
444	}
445	doTestsInlineParam(t, tests, 0, HTML_SAFELINK|HTML_HREF_TARGET_BLANK, HtmlRendererParameters{})
446}
447
448func TestSafeInlineLink(t *testing.T) {
449	var tests = []string{
450		"[foo](/bar/)\n",
451		"<p><a href=\"/bar/\">foo</a></p>\n",
452
453		"[foo](http://bar/)\n",
454		"<p><a href=\"http://bar/\">foo</a></p>\n",
455
456		"[foo](https://bar/)\n",
457		"<p><a href=\"https://bar/\">foo</a></p>\n",
458
459		"[foo](ftp://bar/)\n",
460		"<p><a href=\"ftp://bar/\">foo</a></p>\n",
461
462		"[foo](mailto://bar/)\n",
463		"<p><a href=\"mailto://bar/\">foo</a></p>\n",
464
465		// Not considered safe
466		"[foo](baz://bar/)\n",
467		"<p><tt>foo</tt></p>\n",
468	}
469	doSafeTestsInline(t, tests)
470}
471
472func TestReferenceLink(t *testing.T) {
473	var tests = []string{
474		"[link][ref]\n",
475		"<p>[link][ref]</p>\n",
476
477		"[link][ref]\n   [ref]: /url/ \"title\"\n",
478		"<p><a href=\"/url/\" title=\"title\">link</a></p>\n",
479
480		"[link][ref]\n   [ref]: /url/\n",
481		"<p><a href=\"/url/\">link</a></p>\n",
482
483		"   [ref]: /url/\n",
484		"",
485
486		"   [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n",
487		"",
488
489		"   [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n    [4spaces]: /url/\n",
490		"<pre><code>[4spaces]: /url/\n</code></pre>\n",
491
492		"[hmm](ref2)\n   [ref]: /url/\n[ref2]: /url/\n [ref3]: /url/\n",
493		"<p><a href=\"ref2\">hmm</a></p>\n",
494
495		"[ref]\n",
496		"<p>[ref]</p>\n",
497
498		"[ref]\n   [ref]: /url/ \"title\"\n",
499		"<p><a href=\"/url/\" title=\"title\">ref</a></p>\n",
500	}
501	doLinkTestsInline(t, tests)
502}
503
504func TestTags(t *testing.T) {
505	var tests = []string{
506		"a <span>tag</span>\n",
507		"<p>a <span>tag</span></p>\n",
508
509		"<span>tag</span>\n",
510		"<p><span>tag</span></p>\n",
511
512		"<span>mismatch</spandex>\n",
513		"<p><span>mismatch</spandex></p>\n",
514
515		"a <singleton /> tag\n",
516		"<p>a <singleton /> tag</p>\n",
517	}
518	doTestsInline(t, tests)
519}
520
521func TestAutoLink(t *testing.T) {
522	var tests = []string{
523		"http://foo.com/\n",
524		"<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
525
526		"1 http://foo.com/\n",
527		"<p>1 <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
528
529		"1http://foo.com/\n",
530		"<p>1<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
531
532		"1.http://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		"<ol>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ol>\n",
537
538		"-http://foo.com/\n",
539		"<p>-<a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
540
541		"- http://foo.com/\n",
542		"<ul>\n<li><a href=\"http://foo.com/\">http://foo.com/</a></li>\n</ul>\n",
543
544		"_http://foo.com/\n",
545		"<p>_<a href=\"http://foo.com/\">http://foo.com/</a></p>\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		"ahttp://foo.com/\n",
554		"<p>ahttp://foo.com/</p>\n",
555
556		">http://foo.com/\n",
557		"<blockquote>\n<p><a href=\"http://foo.com/\">http://foo.com/</a></p>\n</blockquote>\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		"go to <http://foo.com/>\n",
563		"<p>go to <a href=\"http://foo.com/\">http://foo.com/</a></p>\n",
564
565		"a secure <https://link.org>\n",
566		"<p>a secure <a href=\"https://link.org\">https://link.org</a></p>\n",
567
568		"an email <mailto:some@one.com>\n",
569		"<p>an email <a href=\"mailto:some@one.com\">some@one.com</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 <some@one.com>\n",
575		"<p>an email <a href=\"mailto:some@one.com\">some@one.com</a></p>\n",
576
577		"an ftp <ftp://old.com>\n",
578		"<p>an ftp <a href=\"ftp://old.com\">ftp://old.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		"a link with <http://new.com?query=foo&bar>\n",
584		"<p>a link with <a href=\"http://new.com?query=foo&amp;bar\">" +
585			"http://new.com?query=foo&amp;bar</a></p>\n",
586
587		"quotes mean a tag <http://new.com?query=\"foo\"&bar>\n",
588		"<p>quotes mean a tag <http://new.com?query=\"foo\"&bar></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		"unless escaped <http://new.com?query=\\\"foo\\\"&bar>\n",
594		"<p>unless escaped <a href=\"http://new.com?query=&quot;foo&quot;&amp;bar\">" +
595			"http://new.com?query=&quot;foo&quot;&amp;bar</a></p>\n",
596
597		"even a > can be escaped <http://new.com?q=\\>&etc>\n",
598		"<p>even a &gt; can be escaped <a href=\"http://new.com?q=&gt;&amp;etc\">" +
599			"http://new.com?q=&gt;&amp;etc</a></p>\n",
600
601		"<a href=\"http://fancy.com\">http://fancy.com</a>\n",
602		"<p><a href=\"http://fancy.com\">http://fancy.com</a></p>\n",
603
604		"<a href=\"http://fancy.com\">This is a link</a>\n",
605		"<p><a href=\"http://fancy.com\">This is a link</a></p>\n",
606
607		"<a href=\"http://www.fancy.com/A_B.pdf\">http://www.fancy.com/A_B.pdf</a>\n",
608		"<p><a href=\"http://www.fancy.com/A_B.pdf\">http://www.fancy.com/A_B.pdf</a></p>\n",
609
610		"(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (\n",
611		"<p>(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (</p>\n",
612
613		"(<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",
614		"<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",
615
616		"http://www.foo.com<br />\n",
617		"<p><a href=\"http://www.foo.com\">http://www.foo.com</a><br /></p>\n",
618
619		"http://foo.com/viewtopic.php?f=18&amp;t=297",
620		"<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",
621
622		"http://foo.com/viewtopic.php?param=&quot;18&quot;zz",
623		"<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",
624
625		"http://foo.com/viewtopic.php?param=&quot;18&quot;",
626		"<p><a href=\"http://foo.com/viewtopic.php?param=&quot;18&quot;\">http://foo.com/viewtopic.php?param=&quot;18&quot;</a></p>\n",
627	}
628	doLinkTestsInline(t, tests)
629}
630
631var footnoteTests = []string{
632	"testing footnotes.[^a]\n\n[^a]: This is the note\n",
633	`<p>testing footnotes.<sup class="footnote-ref" id="fnref:a"><a rel="footnote" href="#fn:a">1</a></sup></p>
634<div class="footnotes">
635
636<hr />
637
638<ol>
639<li id="fn:a">This is the note
640</li>
641</ol>
642</div>
643`,
644
645	`testing long[^b] notes.
646
647[^b]: Paragraph 1
648
649	Paragraph 2
650
651	` + "```\n\tsome code\n\t```" + `
652
653	Paragraph 3
654
655No longer in the footnote
656`,
657	`<p>testing long<sup class="footnote-ref" id="fnref:b"><a rel="footnote" href="#fn:b">1</a></sup> notes.</p>
658
659<p>No longer in the footnote</p>
660<div class="footnotes">
661
662<hr />
663
664<ol>
665<li id="fn:b"><p>Paragraph 1</p>
666
667<p>Paragraph 2</p>
668
669<p><code>
670some code
671</code></p>
672
673<p>Paragraph 3</p>
674</li>
675</ol>
676</div>
677`,
678
679	`testing[^c] multiple[^d] notes.
680
681[^c]: this is [note] c
682
683
684omg
685
686[^d]: this is note d
687
688what happens here
689
690[note]: /link/c
691
692`,
693	`<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>
694
695<p>omg</p>
696
697<p>what happens here</p>
698<div class="footnotes">
699
700<hr />
701
702<ol>
703<li id="fn:c">this is <a href="/link/c">note</a> c
704</li>
705<li id="fn:d">this is note d
706</li>
707</ol>
708</div>
709`,
710
711	"testing inline^[this is the note] notes.\n",
712	`<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>
713<div class="footnotes">
714
715<hr />
716
717<ol>
718<li id="fn:this-is-the-note">this is the note</li>
719</ol>
720</div>
721`,
722
723	"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",
724	`<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>
725<div class="footnotes">
726
727<hr />
728
729<ol>
730<li id="fn:1"><p>the first deferred note</p>
731
732<p>which happens to be a block</p>
733</li>
734<li id="fn:inline-note">inline note</li>
735<li id="fn:2">the second deferred note
736</li>
737</ol>
738</div>
739`,
740
741	`This is a footnote[^1]^[and this is an inline footnote]
742
743[^1]: the footnote text.
744
745    may be multiple paragraphs.
746`,
747	`<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>
748<div class="footnotes">
749
750<hr />
751
752<ol>
753<li id="fn:1"><p>the footnote text.</p>
754
755<p>may be multiple paragraphs.</p>
756</li>
757<li id="fn:and-this-is-an-i">and this is an inline footnote</li>
758</ol>
759</div>
760`,
761
762	"empty footnote[^]\n\n[^]: fn text",
763	"<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",
764}
765
766func TestFootnotes(t *testing.T) {
767	doTestsInlineParam(t, footnoteTests, EXTENSION_FOOTNOTES, 0, HtmlRendererParameters{})
768}
769
770func TestFootnotesWithParameters(t *testing.T) {
771	tests := make([]string, len(footnoteTests))
772
773	prefix := "testPrefix"
774	returnText := "ret"
775	re := regexp.MustCompile(`(?ms)<li id="fn:(\S+?)">(.*?)</li>`)
776
777	// Transform the test expectations to match the parameters we're using.
778	for i, test := range footnoteTests {
779		if i%2 == 1 {
780			test = strings.Replace(test, "fn:", "fn:"+prefix, -1)
781			test = strings.Replace(test, "fnref:", "fnref:"+prefix, -1)
782			test = re.ReplaceAllString(test, `<li id="fn:$1">$2 <a class="footnote-return" href="#fnref:$1">ret</a></li>`)
783		}
784		tests[i] = test
785	}
786
787	params := HtmlRendererParameters{
788		FootnoteAnchorPrefix:       prefix,
789		FootnoteReturnLinkContents: returnText,
790	}
791
792	doTestsInlineParam(t, tests, EXTENSION_FOOTNOTES, HTML_FOOTNOTE_RETURN_LINKS, params)
793}