all repos — grayfriday @ eeb2c39339af374e266bb96592b4313ae1f3b1c9

blackfriday fork with a few changes

block_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 block parsing
  12//
  13
  14package blackfriday
  15
  16import (
  17	"testing"
  18)
  19
  20func runMarkdownBlockWithRenderer(input string, extensions int, renderer Renderer) string {
  21	return string(Markdown([]byte(input), renderer, extensions))
  22}
  23
  24func runMarkdownBlock(input string, extensions int) string {
  25	htmlFlags := 0
  26	htmlFlags |= HTML_USE_XHTML
  27
  28	renderer := HtmlRenderer(htmlFlags, "", "")
  29
  30	return runMarkdownBlockWithRenderer(input, extensions, renderer)
  31}
  32
  33func runnerWithRendererParameters(parameters HtmlRendererParameters) func(string, int) string {
  34	return func(input string, extensions int) string {
  35		htmlFlags := 0
  36		htmlFlags |= HTML_USE_XHTML
  37
  38		renderer := HtmlRendererWithParameters(htmlFlags, "", "", parameters)
  39
  40		return runMarkdownBlockWithRenderer(input, extensions, renderer)
  41	}
  42}
  43
  44func doTestsBlock(t *testing.T, tests []string, extensions int) {
  45	doTestsBlockWithRunner(t, tests, extensions, runMarkdownBlock)
  46}
  47
  48func doTestsBlockWithRunner(t *testing.T, tests []string, extensions int, runner func(string, int) string) {
  49	// catch and report panics
  50	var candidate string
  51	defer func() {
  52		if err := recover(); err != nil {
  53			t.Errorf("\npanic while processing [%#v]: %s\n", candidate, err)
  54		}
  55	}()
  56
  57	for i := 0; i+1 < len(tests); i += 2 {
  58		input := tests[i]
  59		candidate = input
  60		expected := tests[i+1]
  61		actual := runner(candidate, extensions)
  62		if actual != expected {
  63			t.Errorf("\nInput   [%#v]\nExpected[%#v]\nActual  [%#v]",
  64				candidate, expected, actual)
  65		}
  66
  67		// now test every substring to stress test bounds checking
  68		if !testing.Short() {
  69			for start := 0; start < len(input); start++ {
  70				for end := start + 1; end <= len(input); end++ {
  71					candidate = input[start:end]
  72					_ = runMarkdownBlock(candidate, extensions)
  73				}
  74			}
  75		}
  76	}
  77}
  78
  79func TestPrefixHeaderNoExtensions(t *testing.T) {
  80	var tests = []string{
  81		"# Header 1\n",
  82		"<h1>Header 1</h1>\n",
  83
  84		"## Header 2\n",
  85		"<h2>Header 2</h2>\n",
  86
  87		"### Header 3\n",
  88		"<h3>Header 3</h3>\n",
  89
  90		"#### Header 4\n",
  91		"<h4>Header 4</h4>\n",
  92
  93		"##### Header 5\n",
  94		"<h5>Header 5</h5>\n",
  95
  96		"###### Header 6\n",
  97		"<h6>Header 6</h6>\n",
  98
  99		"####### Header 7\n",
 100		"<h6># Header 7</h6>\n",
 101
 102		"#Header 1\n",
 103		"<h1>Header 1</h1>\n",
 104
 105		"##Header 2\n",
 106		"<h2>Header 2</h2>\n",
 107
 108		"###Header 3\n",
 109		"<h3>Header 3</h3>\n",
 110
 111		"####Header 4\n",
 112		"<h4>Header 4</h4>\n",
 113
 114		"#####Header 5\n",
 115		"<h5>Header 5</h5>\n",
 116
 117		"######Header 6\n",
 118		"<h6>Header 6</h6>\n",
 119
 120		"#######Header 7\n",
 121		"<h6>#Header 7</h6>\n",
 122
 123		"Hello\n# Header 1\nGoodbye\n",
 124		"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",
 125
 126		"* List\n# Header\n* List\n",
 127		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 128
 129		"* List\n#Header\n* List\n",
 130		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 131
 132		"*   List\n    * Nested list\n    # Nested header\n",
 133		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
 134			"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
 135
 136		"#Header 1 \\#\n",
 137		"<h1>Header 1 #</h1>\n",
 138
 139		"#Header 1 \\# foo\n",
 140		"<h1>Header 1 # foo</h1>\n",
 141
 142		"#Header 1 #\\##\n",
 143		"<h1>Header 1 ##</h1>\n",
 144	}
 145	doTestsBlock(t, tests, 0)
 146}
 147
 148func TestPrefixHeaderSpaceExtension(t *testing.T) {
 149	var tests = []string{
 150		"# Header 1\n",
 151		"<h1>Header 1</h1>\n",
 152
 153		"## Header 2\n",
 154		"<h2>Header 2</h2>\n",
 155
 156		"### Header 3\n",
 157		"<h3>Header 3</h3>\n",
 158
 159		"#### Header 4\n",
 160		"<h4>Header 4</h4>\n",
 161
 162		"##### Header 5\n",
 163		"<h5>Header 5</h5>\n",
 164
 165		"###### Header 6\n",
 166		"<h6>Header 6</h6>\n",
 167
 168		"####### Header 7\n",
 169		"<p>####### Header 7</p>\n",
 170
 171		"#Header 1\n",
 172		"<p>#Header 1</p>\n",
 173
 174		"##Header 2\n",
 175		"<p>##Header 2</p>\n",
 176
 177		"###Header 3\n",
 178		"<p>###Header 3</p>\n",
 179
 180		"####Header 4\n",
 181		"<p>####Header 4</p>\n",
 182
 183		"#####Header 5\n",
 184		"<p>#####Header 5</p>\n",
 185
 186		"######Header 6\n",
 187		"<p>######Header 6</p>\n",
 188
 189		"#######Header 7\n",
 190		"<p>#######Header 7</p>\n",
 191
 192		"Hello\n# Header 1\nGoodbye\n",
 193		"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",
 194
 195		"* List\n# Header\n* List\n",
 196		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 197
 198		"* List\n#Header\n* List\n",
 199		"<ul>\n<li>List\n#Header</li>\n<li>List</li>\n</ul>\n",
 200
 201		"*   List\n    * Nested list\n    # Nested header\n",
 202		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
 203			"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
 204	}
 205	doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS)
 206}
 207
 208func TestPrefixHeaderIdExtension(t *testing.T) {
 209	var tests = []string{
 210		"# Header 1 {#someid}\n",
 211		"<h1 id=\"someid\">Header 1</h1>\n",
 212
 213		"# Header 1 {#someid}   \n",
 214		"<h1 id=\"someid\">Header 1</h1>\n",
 215
 216		"# Header 1         {#someid}\n",
 217		"<h1 id=\"someid\">Header 1</h1>\n",
 218
 219		"# Header 1 {#someid\n",
 220		"<h1>Header 1 {#someid</h1>\n",
 221
 222		"# Header 1 {#someid\n",
 223		"<h1>Header 1 {#someid</h1>\n",
 224
 225		"# Header 1 {#someid}}\n",
 226		"<h1 id=\"someid\">Header 1</h1>\n\n<p>}</p>\n",
 227
 228		"## Header 2 {#someid}\n",
 229		"<h2 id=\"someid\">Header 2</h2>\n",
 230
 231		"### Header 3 {#someid}\n",
 232		"<h3 id=\"someid\">Header 3</h3>\n",
 233
 234		"#### Header 4 {#someid}\n",
 235		"<h4 id=\"someid\">Header 4</h4>\n",
 236
 237		"##### Header 5 {#someid}\n",
 238		"<h5 id=\"someid\">Header 5</h5>\n",
 239
 240		"###### Header 6 {#someid}\n",
 241		"<h6 id=\"someid\">Header 6</h6>\n",
 242
 243		"####### Header 7 {#someid}\n",
 244		"<h6 id=\"someid\"># Header 7</h6>\n",
 245
 246		"# Header 1 # {#someid}\n",
 247		"<h1 id=\"someid\">Header 1</h1>\n",
 248
 249		"## Header 2 ## {#someid}\n",
 250		"<h2 id=\"someid\">Header 2</h2>\n",
 251
 252		"Hello\n# Header 1\nGoodbye\n",
 253		"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",
 254
 255		"* List\n# Header {#someid}\n* List\n",
 256		"<ul>\n<li><p>List</p>\n\n<h1 id=\"someid\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 257
 258		"* List\n#Header {#someid}\n* List\n",
 259		"<ul>\n<li><p>List</p>\n\n<h1 id=\"someid\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 260
 261		"*   List\n    * Nested list\n    # Nested header {#someid}\n",
 262		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
 263			"<h1 id=\"someid\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
 264	}
 265	doTestsBlock(t, tests, EXTENSION_HEADER_IDS)
 266}
 267
 268func TestPrefixHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {
 269	var tests = []string{
 270		"# header 1 {#someid}\n",
 271		"<h1 id=\"PRE:someid:POST\">header 1</h1>\n",
 272
 273		"## header 2 {#someid}\n",
 274		"<h2 id=\"PRE:someid:POST\">header 2</h2>\n",
 275
 276		"### header 3 {#someid}\n",
 277		"<h3 id=\"PRE:someid:POST\">header 3</h3>\n",
 278
 279		"#### header 4 {#someid}\n",
 280		"<h4 id=\"PRE:someid:POST\">header 4</h4>\n",
 281
 282		"##### header 5 {#someid}\n",
 283		"<h5 id=\"PRE:someid:POST\">header 5</h5>\n",
 284
 285		"###### header 6 {#someid}\n",
 286		"<h6 id=\"PRE:someid:POST\">header 6</h6>\n",
 287
 288		"####### header 7 {#someid}\n",
 289		"<h6 id=\"PRE:someid:POST\"># header 7</h6>\n",
 290
 291		"# header 1 # {#someid}\n",
 292		"<h1 id=\"PRE:someid:POST\">header 1</h1>\n",
 293
 294		"## header 2 ## {#someid}\n",
 295		"<h2 id=\"PRE:someid:POST\">header 2</h2>\n",
 296
 297		"* List\n# Header {#someid}\n* List\n",
 298		"<ul>\n<li><p>List</p>\n\n<h1 id=\"PRE:someid:POST\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 299
 300		"* List\n#Header {#someid}\n* List\n",
 301		"<ul>\n<li><p>List</p>\n\n<h1 id=\"PRE:someid:POST\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 302
 303		"*   List\n    * Nested list\n    # Nested header {#someid}\n",
 304		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
 305			"<h1 id=\"PRE:someid:POST\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
 306	}
 307
 308	parameters := HtmlRendererParameters{
 309		HeaderIDPrefix: "PRE:",
 310		HeaderIDSuffix: ":POST",
 311	}
 312
 313	doTestsBlockWithRunner(t, tests, EXTENSION_HEADER_IDS, runnerWithRendererParameters(parameters))
 314}
 315
 316func TestPrefixAutoHeaderIdExtension(t *testing.T) {
 317	var tests = []string{
 318		"# Header 1\n",
 319		"<h1 id=\"header-1\">Header 1</h1>\n",
 320
 321		"# Header 1   \n",
 322		"<h1 id=\"header-1\">Header 1</h1>\n",
 323
 324		"## Header 2\n",
 325		"<h2 id=\"header-2\">Header 2</h2>\n",
 326
 327		"### Header 3\n",
 328		"<h3 id=\"header-3\">Header 3</h3>\n",
 329
 330		"#### Header 4\n",
 331		"<h4 id=\"header-4\">Header 4</h4>\n",
 332
 333		"##### Header 5\n",
 334		"<h5 id=\"header-5\">Header 5</h5>\n",
 335
 336		"###### Header 6\n",
 337		"<h6 id=\"header-6\">Header 6</h6>\n",
 338
 339		"####### Header 7\n",
 340		"<h6 id=\"header-7\"># Header 7</h6>\n",
 341
 342		"Hello\n# Header 1\nGoodbye\n",
 343		"<p>Hello</p>\n\n<h1 id=\"header-1\">Header 1</h1>\n\n<p>Goodbye</p>\n",
 344
 345		"* List\n# Header\n* List\n",
 346		"<ul>\n<li><p>List</p>\n\n<h1 id=\"header\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 347
 348		"* List\n#Header\n* List\n",
 349		"<ul>\n<li><p>List</p>\n\n<h1 id=\"header\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 350
 351		"*   List\n    * Nested list\n    # Nested header\n",
 352		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
 353			"<h1 id=\"nested-header\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
 354
 355		"# Header\n\n# Header\n",
 356		"<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n",
 357
 358		"# Header 1\n\n# Header 1",
 359		"<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",
 360
 361		"# Header\n\n# Header 1\n\n# Header\n\n# Header",
 362		"<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header</h1>\n\n<h1 id=\"header-1-2\">Header</h1>\n",
 363	}
 364	doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS)
 365}
 366
 367func TestPrefixAutoHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {
 368	var tests = []string{
 369		"# Header 1\n",
 370		"<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n",
 371
 372		"# Header 1   \n",
 373		"<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n",
 374
 375		"## Header 2\n",
 376		"<h2 id=\"PRE:header-2:POST\">Header 2</h2>\n",
 377
 378		"### Header 3\n",
 379		"<h3 id=\"PRE:header-3:POST\">Header 3</h3>\n",
 380
 381		"#### Header 4\n",
 382		"<h4 id=\"PRE:header-4:POST\">Header 4</h4>\n",
 383
 384		"##### Header 5\n",
 385		"<h5 id=\"PRE:header-5:POST\">Header 5</h5>\n",
 386
 387		"###### Header 6\n",
 388		"<h6 id=\"PRE:header-6:POST\">Header 6</h6>\n",
 389
 390		"####### Header 7\n",
 391		"<h6 id=\"PRE:header-7:POST\"># Header 7</h6>\n",
 392
 393		"Hello\n# Header 1\nGoodbye\n",
 394		"<p>Hello</p>\n\n<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<p>Goodbye</p>\n",
 395
 396		"* List\n# Header\n* List\n",
 397		"<ul>\n<li><p>List</p>\n\n<h1 id=\"PRE:header:POST\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 398
 399		"* List\n#Header\n* List\n",
 400		"<ul>\n<li><p>List</p>\n\n<h1 id=\"PRE:header:POST\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
 401
 402		"*   List\n    * Nested list\n    # Nested header\n",
 403		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
 404			"<h1 id=\"PRE:nested-header:POST\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
 405
 406		"# Header\n\n# Header\n",
 407		"<h1 id=\"PRE:header:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1:POST\">Header</h1>\n",
 408
 409		"# Header 1\n\n# Header 1",
 410		"<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<h1 id=\"PRE:header-1-1:POST\">Header 1</h1>\n",
 411
 412		"# Header\n\n# Header 1\n\n# Header\n\n# Header",
 413		"<h1 id=\"PRE:header:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<h1 id=\"PRE:header-1-1:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1-2:POST\">Header</h1>\n",
 414	}
 415
 416	parameters := HtmlRendererParameters{
 417		HeaderIDPrefix: "PRE:",
 418		HeaderIDSuffix: ":POST",
 419	}
 420
 421	doTestsBlockWithRunner(t, tests, EXTENSION_AUTO_HEADER_IDS, runnerWithRendererParameters(parameters))
 422}
 423
 424func TestPrefixMultipleHeaderExtensions(t *testing.T) {
 425	var tests = []string{
 426		"# Header\n\n# Header {#header}\n\n# Header 1",
 427		"<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",
 428	}
 429	doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS|EXTENSION_HEADER_IDS)
 430}
 431
 432func TestUnderlineHeaders(t *testing.T) {
 433	var tests = []string{
 434		"Header 1\n========\n",
 435		"<h1>Header 1</h1>\n",
 436
 437		"Header 2\n--------\n",
 438		"<h2>Header 2</h2>\n",
 439
 440		"A\n=\n",
 441		"<h1>A</h1>\n",
 442
 443		"B\n-\n",
 444		"<h2>B</h2>\n",
 445
 446		"Paragraph\nHeader\n=\n",
 447		"<p>Paragraph</p>\n\n<h1>Header</h1>\n",
 448
 449		"Header\n===\nParagraph\n",
 450		"<h1>Header</h1>\n\n<p>Paragraph</p>\n",
 451
 452		"Header\n===\nAnother header\n---\n",
 453		"<h1>Header</h1>\n\n<h2>Another header</h2>\n",
 454
 455		"   Header\n======\n",
 456		"<h1>Header</h1>\n",
 457
 458		"    Code\n========\n",
 459		"<pre><code>Code\n</code></pre>\n\n<p>========</p>\n",
 460
 461		"Header with *inline*\n=====\n",
 462		"<h1>Header with <em>inline</em></h1>\n",
 463
 464		"*   List\n    * Sublist\n    Not a header\n    ------\n",
 465		"<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",
 466
 467		"Paragraph\n\n\n\n\nHeader\n===\n",
 468		"<p>Paragraph</p>\n\n<h1>Header</h1>\n",
 469
 470		"Trailing space \n====        \n\n",
 471		"<h1>Trailing space</h1>\n",
 472
 473		"Trailing spaces\n====        \n\n",
 474		"<h1>Trailing spaces</h1>\n",
 475
 476		"Double underline\n=====\n=====\n",
 477		"<h1>Double underline</h1>\n\n<p>=====</p>\n",
 478	}
 479	doTestsBlock(t, tests, 0)
 480}
 481
 482func TestUnderlineHeadersAutoIDs(t *testing.T) {
 483	var tests = []string{
 484		"Header 1\n========\n",
 485		"<h1 id=\"header-1\">Header 1</h1>\n",
 486
 487		"Header 2\n--------\n",
 488		"<h2 id=\"header-2\">Header 2</h2>\n",
 489
 490		"A\n=\n",
 491		"<h1 id=\"a\">A</h1>\n",
 492
 493		"B\n-\n",
 494		"<h2 id=\"b\">B</h2>\n",
 495
 496		"Paragraph\nHeader\n=\n",
 497		"<p>Paragraph</p>\n\n<h1 id=\"header\">Header</h1>\n",
 498
 499		"Header\n===\nParagraph\n",
 500		"<h1 id=\"header\">Header</h1>\n\n<p>Paragraph</p>\n",
 501
 502		"Header\n===\nAnother header\n---\n",
 503		"<h1 id=\"header\">Header</h1>\n\n<h2 id=\"another-header\">Another header</h2>\n",
 504
 505		"   Header\n======\n",
 506		"<h1 id=\"header\">Header</h1>\n",
 507
 508		"Header with *inline*\n=====\n",
 509		"<h1 id=\"header-with-inline\">Header with <em>inline</em></h1>\n",
 510
 511		"Paragraph\n\n\n\n\nHeader\n===\n",
 512		"<p>Paragraph</p>\n\n<h1 id=\"header\">Header</h1>\n",
 513
 514		"Trailing space \n====        \n\n",
 515		"<h1 id=\"trailing-space\">Trailing space</h1>\n",
 516
 517		"Trailing spaces\n====        \n\n",
 518		"<h1 id=\"trailing-spaces\">Trailing spaces</h1>\n",
 519
 520		"Double underline\n=====\n=====\n",
 521		"<h1 id=\"double-underline\">Double underline</h1>\n\n<p>=====</p>\n",
 522
 523		"Header\n======\n\nHeader\n======\n",
 524		"<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n",
 525
 526		"Header 1\n========\n\nHeader 1\n========\n",
 527		"<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",
 528	}
 529	doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS)
 530}
 531
 532func TestHorizontalRule(t *testing.T) {
 533	var tests = []string{
 534		"-\n",
 535		"<p>-</p>\n",
 536
 537		"--\n",
 538		"<p>--</p>\n",
 539
 540		"---\n",
 541		"<hr />\n",
 542
 543		"----\n",
 544		"<hr />\n",
 545
 546		"*\n",
 547		"<p>*</p>\n",
 548
 549		"**\n",
 550		"<p>**</p>\n",
 551
 552		"***\n",
 553		"<hr />\n",
 554
 555		"****\n",
 556		"<hr />\n",
 557
 558		"_\n",
 559		"<p>_</p>\n",
 560
 561		"__\n",
 562		"<p>__</p>\n",
 563
 564		"___\n",
 565		"<hr />\n",
 566
 567		"____\n",
 568		"<hr />\n",
 569
 570		"-*-\n",
 571		"<p>-*-</p>\n",
 572
 573		"- - -\n",
 574		"<hr />\n",
 575
 576		"* * *\n",
 577		"<hr />\n",
 578
 579		"_ _ _\n",
 580		"<hr />\n",
 581
 582		"-----*\n",
 583		"<p>-----*</p>\n",
 584
 585		"   ------   \n",
 586		"<hr />\n",
 587
 588		"Hello\n***\n",
 589		"<p>Hello</p>\n\n<hr />\n",
 590
 591		"---\n***\n___\n",
 592		"<hr />\n\n<hr />\n\n<hr />\n",
 593	}
 594	doTestsBlock(t, tests, 0)
 595}
 596
 597func TestUnorderedList(t *testing.T) {
 598	var tests = []string{
 599		"* Hello\n",
 600		"<ul>\n<li>Hello</li>\n</ul>\n",
 601
 602		"* Yin\n* Yang\n",
 603		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
 604
 605		"* Ting\n* Bong\n* Goo\n",
 606		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
 607
 608		"* Yin\n\n* Yang\n",
 609		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
 610
 611		"* Ting\n\n* Bong\n* Goo\n",
 612		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
 613
 614		"+ Hello\n",
 615		"<ul>\n<li>Hello</li>\n</ul>\n",
 616
 617		"+ Yin\n+ Yang\n",
 618		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
 619
 620		"+ Ting\n+ Bong\n+ Goo\n",
 621		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
 622
 623		"+ Yin\n\n+ Yang\n",
 624		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
 625
 626		"+ Ting\n\n+ Bong\n+ Goo\n",
 627		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
 628
 629		"- Hello\n",
 630		"<ul>\n<li>Hello</li>\n</ul>\n",
 631
 632		"- Yin\n- Yang\n",
 633		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
 634
 635		"- Ting\n- Bong\n- Goo\n",
 636		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
 637
 638		"- Yin\n\n- Yang\n",
 639		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
 640
 641		"- Ting\n\n- Bong\n- Goo\n",
 642		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
 643
 644		"*Hello\n",
 645		"<p>*Hello</p>\n",
 646
 647		"*   Hello \n",
 648		"<ul>\n<li>Hello</li>\n</ul>\n",
 649
 650		"*   Hello \n    Next line \n",
 651		"<ul>\n<li>Hello\nNext line</li>\n</ul>\n",
 652
 653		"Paragraph\n* No linebreak\n",
 654		"<p>Paragraph\n* No linebreak</p>\n",
 655
 656		"Paragraph\n\n* Linebreak\n",
 657		"<p>Paragraph</p>\n\n<ul>\n<li>Linebreak</li>\n</ul>\n",
 658
 659		"*   List\n    * Nested list\n",
 660		"<ul>\n<li>List\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",
 661
 662		"*   List\n\n    * Nested list\n",
 663		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",
 664
 665		"*   List\n    Second line\n\n    + Nested\n",
 666		"<ul>\n<li><p>List\nSecond line</p>\n\n<ul>\n<li>Nested</li>\n</ul></li>\n</ul>\n",
 667
 668		"*   List\n    + Nested\n\n    Continued\n",
 669		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested</li>\n</ul>\n\n<p>Continued</p></li>\n</ul>\n",
 670
 671		"*   List\n   * shallow indent\n",
 672		"<ul>\n<li>List\n\n<ul>\n<li>shallow indent</li>\n</ul></li>\n</ul>\n",
 673
 674		"* List\n" +
 675			" * shallow indent\n" +
 676			"  * part of second list\n" +
 677			"   * still second\n" +
 678			"    * almost there\n" +
 679			"     * third level\n",
 680		"<ul>\n" +
 681			"<li>List\n\n" +
 682			"<ul>\n" +
 683			"<li>shallow indent</li>\n" +
 684			"<li>part of second list</li>\n" +
 685			"<li>still second</li>\n" +
 686			"<li>almost there\n\n" +
 687			"<ul>\n" +
 688			"<li>third level</li>\n" +
 689			"</ul></li>\n" +
 690			"</ul></li>\n" +
 691			"</ul>\n",
 692
 693		"* List\n        extra indent, same paragraph\n",
 694		"<ul>\n<li>List\n    extra indent, same paragraph</li>\n</ul>\n",
 695
 696		"* List\n\n        code block\n",
 697		"<ul>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ul>\n",
 698
 699		"* List\n\n          code block with spaces\n",
 700		"<ul>\n<li><p>List</p>\n\n<pre><code>  code block with spaces\n</code></pre></li>\n</ul>\n",
 701
 702		"* List\n\n    * sublist\n\n    normal text\n\n    * another sublist\n",
 703		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>sublist</li>\n</ul>\n\n<p>normal text</p>\n\n<ul>\n<li>another sublist</li>\n</ul></li>\n</ul>\n",
 704	}
 705	doTestsBlock(t, tests, 0)
 706}
 707
 708func TestOrderedList(t *testing.T) {
 709	var tests = []string{
 710		"1. Hello\n",
 711		"<ol>\n<li>Hello</li>\n</ol>\n",
 712
 713		"1. Yin\n2. Yang\n",
 714		"<ol>\n<li>Yin</li>\n<li>Yang</li>\n</ol>\n",
 715
 716		"1. Ting\n2. Bong\n3. Goo\n",
 717		"<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n",
 718
 719		"1. Yin\n\n2. Yang\n",
 720		"<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n",
 721
 722		"1. Ting\n\n2. Bong\n3. Goo\n",
 723		"<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n",
 724
 725		"1 Hello\n",
 726		"<p>1 Hello</p>\n",
 727
 728		"1.Hello\n",
 729		"<p>1.Hello</p>\n",
 730
 731		"1.  Hello \n",
 732		"<ol>\n<li>Hello</li>\n</ol>\n",
 733
 734		"1.  Hello \n    Next line \n",
 735		"<ol>\n<li>Hello\nNext line</li>\n</ol>\n",
 736
 737		"Paragraph\n1. No linebreak\n",
 738		"<p>Paragraph\n1. No linebreak</p>\n",
 739
 740		"Paragraph\n\n1. Linebreak\n",
 741		"<p>Paragraph</p>\n\n<ol>\n<li>Linebreak</li>\n</ol>\n",
 742
 743		"1.  List\n    1. Nested list\n",
 744		"<ol>\n<li>List\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",
 745
 746		"1.  List\n\n    1. Nested list\n",
 747		"<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",
 748
 749		"1.  List\n    Second line\n\n    1. Nested\n",
 750		"<ol>\n<li><p>List\nSecond line</p>\n\n<ol>\n<li>Nested</li>\n</ol></li>\n</ol>\n",
 751
 752		"1.  List\n    1. Nested\n\n    Continued\n",
 753		"<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested</li>\n</ol>\n\n<p>Continued</p></li>\n</ol>\n",
 754
 755		"1.  List\n   1. shallow indent\n",
 756		"<ol>\n<li>List\n\n<ol>\n<li>shallow indent</li>\n</ol></li>\n</ol>\n",
 757
 758		"1. List\n" +
 759			" 1. shallow indent\n" +
 760			"  2. part of second list\n" +
 761			"   3. still second\n" +
 762			"    4. almost there\n" +
 763			"     1. third level\n",
 764		"<ol>\n" +
 765			"<li>List\n\n" +
 766			"<ol>\n" +
 767			"<li>shallow indent</li>\n" +
 768			"<li>part of second list</li>\n" +
 769			"<li>still second</li>\n" +
 770			"<li>almost there\n\n" +
 771			"<ol>\n" +
 772			"<li>third level</li>\n" +
 773			"</ol></li>\n" +
 774			"</ol></li>\n" +
 775			"</ol>\n",
 776
 777		"1. List\n        extra indent, same paragraph\n",
 778		"<ol>\n<li>List\n    extra indent, same paragraph</li>\n</ol>\n",
 779
 780		"1. List\n\n        code block\n",
 781		"<ol>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ol>\n",
 782
 783		"1. List\n\n          code block with spaces\n",
 784		"<ol>\n<li><p>List</p>\n\n<pre><code>  code block with spaces\n</code></pre></li>\n</ol>\n",
 785
 786		"1. List\n    * Mixted list\n",
 787		"<ol>\n<li>List\n\n<ul>\n<li>Mixted list</li>\n</ul></li>\n</ol>\n",
 788
 789		"1. List\n * Mixed list\n",
 790		"<ol>\n<li>List\n\n<ul>\n<li>Mixed list</li>\n</ul></li>\n</ol>\n",
 791
 792		"* Start with unordered\n 1. Ordered\n",
 793		"<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",
 794
 795		"* Start with unordered\n    1. Ordered\n",
 796		"<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",
 797
 798		"1. numbers\n1. are ignored\n",
 799		"<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n",
 800	}
 801	doTestsBlock(t, tests, 0)
 802}
 803
 804func TestPreformattedHtml(t *testing.T) {
 805	var tests = []string{
 806		"<div></div>\n",
 807		"<div></div>\n",
 808
 809		"<div>\n</div>\n",
 810		"<div>\n</div>\n",
 811
 812		"<div>\n</div>\nParagraph\n",
 813		"<p><div>\n</div>\nParagraph</p>\n",
 814
 815		"<div class=\"foo\">\n</div>\n",
 816		"<div class=\"foo\">\n</div>\n",
 817
 818		"<div>\nAnything here\n</div>\n",
 819		"<div>\nAnything here\n</div>\n",
 820
 821		"<div>\n  Anything here\n</div>\n",
 822		"<div>\n  Anything here\n</div>\n",
 823
 824		"<div>\nAnything here\n  </div>\n",
 825		"<div>\nAnything here\n  </div>\n",
 826
 827		"<div>\nThis is *not* &proceessed\n</div>\n",
 828		"<div>\nThis is *not* &proceessed\n</div>\n",
 829
 830		"<faketag>\n  Something\n</faketag>\n",
 831		"<p><faketag>\n  Something\n</faketag></p>\n",
 832
 833		"<div>\n  Something here\n</divv>\n",
 834		"<p><div>\n  Something here\n</divv></p>\n",
 835
 836		"Paragraph\n<div>\nHere? >&<\n</div>\n",
 837		"<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div></p>\n",
 838
 839		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n",
 840		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n",
 841
 842		"Paragraph\n<div>\nHere? >&<\n</div>\nAnd here?\n",
 843		"<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div>\nAnd here?</p>\n",
 844
 845		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\nAnd here?\n",
 846		"<p>Paragraph</p>\n\n<p><div>\nHow about here? &gt;&amp;&lt;\n</div>\nAnd here?</p>\n",
 847
 848		"Paragraph\n<div>\nHere? >&<\n</div>\n\nAnd here?\n",
 849		"<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div></p>\n\n<p>And here?</p>\n",
 850
 851		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n",
 852		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",
 853	}
 854	doTestsBlock(t, tests, 0)
 855}
 856
 857func TestPreformattedHtmlLax(t *testing.T) {
 858	var tests = []string{
 859		"Paragraph\n<div>\nHere? >&<\n</div>\n",
 860		"<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n",
 861
 862		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n",
 863		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n",
 864
 865		"Paragraph\n<div>\nHere? >&<\n</div>\nAnd here?\n",
 866		"<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n\n<p>And here?</p>\n",
 867
 868		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\nAnd here?\n",
 869		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",
 870
 871		"Paragraph\n<div>\nHere? >&<\n</div>\n\nAnd here?\n",
 872		"<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n\n<p>And here?</p>\n",
 873
 874		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n",
 875		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",
 876	}
 877	doTestsBlock(t, tests, EXTENSION_LAX_HTML_BLOCKS)
 878}
 879
 880func TestFencedCodeBlock(t *testing.T) {
 881	var tests = []string{
 882		"``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",
 883		"<pre><code class=\"language-go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",
 884
 885		"``` c\n/* special & char < > \" escaping */\n```\n",
 886		"<pre><code class=\"language-c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",
 887
 888		"``` c\nno *inline* processing ~~of text~~\n```\n",
 889		"<pre><code class=\"language-c\">no *inline* processing ~~of text~~\n</code></pre>\n",
 890
 891		"```\nNo language\n```\n",
 892		"<pre><code>No language\n</code></pre>\n",
 893
 894		"``` {ocaml}\nlanguage in braces\n```\n",
 895		"<pre><code class=\"language-ocaml\">language in braces\n</code></pre>\n",
 896
 897		"```    {ocaml}      \nwith extra whitespace\n```\n",
 898		"<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",
 899
 900		"```{   ocaml   }\nwith extra whitespace\n```\n",
 901		"<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",
 902
 903		"~ ~~ java\nWith whitespace\n~~~\n",
 904		"<p>~ ~~ java\nWith whitespace\n~~~</p>\n",
 905
 906		"~~\nonly two\n~~\n",
 907		"<p>~~\nonly two\n~~</p>\n",
 908
 909		"```` python\nextra\n````\n",
 910		"<pre><code class=\"language-python\">extra\n</code></pre>\n",
 911
 912		"~~~ perl\nthree to start, four to end\n~~~~\n",
 913		"<p>~~~ perl\nthree to start, four to end\n~~~~</p>\n",
 914
 915		"~~~~ perl\nfour to start, three to end\n~~~\n",
 916		"<p>~~~~ perl\nfour to start, three to end\n~~~</p>\n",
 917
 918		"~~~ bash\ntildes\n~~~\n",
 919		"<pre><code class=\"language-bash\">tildes\n</code></pre>\n",
 920
 921		"``` lisp\nno ending\n",
 922		"<p>``` lisp\nno ending</p>\n",
 923
 924		"~~~ lisp\nend with language\n~~~ lisp\n",
 925		"<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",
 926
 927		"```\nmismatched begin and end\n~~~\n",
 928		"<p>```\nmismatched begin and end\n~~~</p>\n",
 929
 930		"~~~\nmismatched begin and end\n```\n",
 931		"<p>~~~\nmismatched begin and end\n```</p>\n",
 932
 933		"   ``` oz\nleading spaces\n```\n",
 934		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
 935
 936		"  ``` oz\nleading spaces\n ```\n",
 937		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
 938
 939		" ``` oz\nleading spaces\n  ```\n",
 940		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
 941
 942		"``` oz\nleading spaces\n   ```\n",
 943		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
 944
 945		"    ``` oz\nleading spaces\n    ```\n",
 946		"<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces\n    ```</p>\n",
 947
 948		"Bla bla\n\n``` oz\ncode blocks breakup paragraphs\n```\n\nBla Bla\n",
 949		"<p>Bla bla</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Bla Bla</p>\n",
 950
 951		"Some text before a fenced code block\n``` oz\ncode blocks breakup paragraphs\n```\nAnd some text after a fenced code block",
 952		"<p>Some text before a fenced code block</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>And some text after a fenced code block</p>\n",
 953
 954		"`",
 955		"<p>`</p>\n",
 956
 957		"Bla bla\n\n``` oz\ncode blocks breakup paragraphs\n```\n\nBla Bla\n\n``` oz\nmultiple code blocks work okay\n```\n\nBla Bla\n",
 958		"<p>Bla bla</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Bla Bla</p>\n\n<pre><code class=\"language-oz\">multiple code blocks work okay\n</code></pre>\n\n<p>Bla Bla</p>\n",
 959
 960		"Some text before a fenced code block\n``` oz\ncode blocks breakup paragraphs\n```\nSome text in between\n``` oz\nmultiple code blocks work okay\n```\nAnd some text after a fenced code block",
 961		"<p>Some text before a fenced code block</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Some text in between</p>\n\n<pre><code class=\"language-oz\">multiple code blocks work okay\n</code></pre>\n\n<p>And some text after a fenced code block</p>\n",
 962	}
 963	doTestsBlock(t, tests, EXTENSION_FENCED_CODE)
 964}
 965
 966func TestTable(t *testing.T) {
 967	var tests = []string{
 968		"a | b\n---|---\nc | d\n",
 969		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n\n" +
 970			"<tbody>\n<tr>\n<td>c</td>\n<td>d</td>\n</tr>\n</tbody>\n</table>\n",
 971
 972		"a | b\n---|--\nc | d\n",
 973		"<p>a | b\n---|--\nc | d</p>\n",
 974
 975		"|a|b|c|d|\n|----|----|----|---|\n|e|f|g|h|\n",
 976		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n<th>d</th>\n</tr>\n</thead>\n\n" +
 977			"<tbody>\n<tr>\n<td>e</td>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n",
 978
 979		"*a*|__b__|[c](C)|d\n---|---|---|---\ne|f|g|h\n",
 980		"<table>\n<thead>\n<tr>\n<th><em>a</em></th>\n<th><strong>b</strong></th>\n<th><a href=\"C\">c</a></th>\n<th>d</th>\n</tr>\n</thead>\n\n" +
 981			"<tbody>\n<tr>\n<td>e</td>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n",
 982
 983		"a|b|c\n---|---|---\nd|e|f\ng|h\ni|j|k|l|m\nn|o|p\n",
 984		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" +
 985			"<tbody>\n<tr>\n<td>d</td>\n<td>e</td>\n<td>f</td>\n</tr>\n\n" +
 986			"<tr>\n<td>g</td>\n<td>h</td>\n<td></td>\n</tr>\n\n" +
 987			"<tr>\n<td>i</td>\n<td>j</td>\n<td>k</td>\n</tr>\n\n" +
 988			"<tr>\n<td>n</td>\n<td>o</td>\n<td>p</td>\n</tr>\n</tbody>\n</table>\n",
 989
 990		"a|b|c\n---|---|---\n*d*|__e__|f\n",
 991		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" +
 992			"<tbody>\n<tr>\n<td><em>d</em></td>\n<td><strong>e</strong></td>\n<td>f</td>\n</tr>\n</tbody>\n</table>\n",
 993
 994		"a|b|c|d\n:--|--:|:-:|---\ne|f|g|h\n",
 995		"<table>\n<thead>\n<tr>\n<th align=\"left\">a</th>\n<th align=\"right\">b</th>\n" +
 996			"<th align=\"center\">c</th>\n<th>d</th>\n</tr>\n</thead>\n\n" +
 997			"<tbody>\n<tr>\n<td align=\"left\">e</td>\n<td align=\"right\">f</td>\n" +
 998			"<td align=\"center\">g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n",
 999
1000		"a|b|c\n---|---|---\n",
1001		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n<tbody>\n</tbody>\n</table>\n",
1002
1003		"a| b|c | d | e\n---|---|---|---|---\nf| g|h | i |j\n",
1004		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n<th>d</th>\n<th>e</th>\n</tr>\n</thead>\n\n" +
1005			"<tbody>\n<tr>\n<td>f</td>\n<td>g</td>\n<td>h</td>\n<td>i</td>\n<td>j</td>\n</tr>\n</tbody>\n</table>\n",
1006
1007		"a|b\\|c|d\n---|---|---\nf|g\\|h|i\n",
1008		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b|c</th>\n<th>d</th>\n</tr>\n</thead>\n\n<tbody>\n<tr>\n<td>f</td>\n<td>g|h</td>\n<td>i</td>\n</tr>\n</tbody>\n</table>\n",
1009	}
1010	doTestsBlock(t, tests, EXTENSION_TABLES)
1011}
1012
1013func TestUnorderedListWith_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
1014	var tests = []string{
1015		"* Hello\n",
1016		"<ul>\n<li>Hello</li>\n</ul>\n",
1017
1018		"* Yin\n* Yang\n",
1019		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
1020
1021		"* Ting\n* Bong\n* Goo\n",
1022		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
1023
1024		"* Yin\n\n* Yang\n",
1025		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
1026
1027		"* Ting\n\n* Bong\n* Goo\n",
1028		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
1029
1030		"+ Hello\n",
1031		"<ul>\n<li>Hello</li>\n</ul>\n",
1032
1033		"+ Yin\n+ Yang\n",
1034		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
1035
1036		"+ Ting\n+ Bong\n+ Goo\n",
1037		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
1038
1039		"+ Yin\n\n+ Yang\n",
1040		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
1041
1042		"+ Ting\n\n+ Bong\n+ Goo\n",
1043		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
1044
1045		"- Hello\n",
1046		"<ul>\n<li>Hello</li>\n</ul>\n",
1047
1048		"- Yin\n- Yang\n",
1049		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
1050
1051		"- Ting\n- Bong\n- Goo\n",
1052		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
1053
1054		"- Yin\n\n- Yang\n",
1055		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
1056
1057		"- Ting\n\n- Bong\n- Goo\n",
1058		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
1059
1060		"*Hello\n",
1061		"<p>*Hello</p>\n",
1062
1063		"*   Hello \n",
1064		"<ul>\n<li>Hello</li>\n</ul>\n",
1065
1066		"*   Hello \n    Next line \n",
1067		"<ul>\n<li>Hello\nNext line</li>\n</ul>\n",
1068
1069		"Paragraph\n* No linebreak\n",
1070		"<p>Paragraph</p>\n\n<ul>\n<li>No linebreak</li>\n</ul>\n",
1071
1072		"Paragraph\n\n* Linebreak\n",
1073		"<p>Paragraph</p>\n\n<ul>\n<li>Linebreak</li>\n</ul>\n",
1074
1075		"*   List\n    * Nested list\n",
1076		"<ul>\n<li>List\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",
1077
1078		"*   List\n\n    * Nested list\n",
1079		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",
1080
1081		"*   List\n    Second line\n\n    + Nested\n",
1082		"<ul>\n<li><p>List\nSecond line</p>\n\n<ul>\n<li>Nested</li>\n</ul></li>\n</ul>\n",
1083
1084		"*   List\n    + Nested\n\n    Continued\n",
1085		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested</li>\n</ul>\n\n<p>Continued</p></li>\n</ul>\n",
1086
1087		"*   List\n   * shallow indent\n",
1088		"<ul>\n<li>List\n\n<ul>\n<li>shallow indent</li>\n</ul></li>\n</ul>\n",
1089
1090		"* List\n" +
1091			" * shallow indent\n" +
1092			"  * part of second list\n" +
1093			"   * still second\n" +
1094			"    * almost there\n" +
1095			"     * third level\n",
1096		"<ul>\n" +
1097			"<li>List\n\n" +
1098			"<ul>\n" +
1099			"<li>shallow indent</li>\n" +
1100			"<li>part of second list</li>\n" +
1101			"<li>still second</li>\n" +
1102			"<li>almost there\n\n" +
1103			"<ul>\n" +
1104			"<li>third level</li>\n" +
1105			"</ul></li>\n" +
1106			"</ul></li>\n" +
1107			"</ul>\n",
1108
1109		"* List\n        extra indent, same paragraph\n",
1110		"<ul>\n<li>List\n    extra indent, same paragraph</li>\n</ul>\n",
1111
1112		"* List\n\n        code block\n",
1113		"<ul>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ul>\n",
1114
1115		"* List\n\n          code block with spaces\n",
1116		"<ul>\n<li><p>List</p>\n\n<pre><code>  code block with spaces\n</code></pre></li>\n</ul>\n",
1117
1118		"* List\n\n    * sublist\n\n    normal text\n\n    * another sublist\n",
1119		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>sublist</li>\n</ul>\n\n<p>normal text</p>\n\n<ul>\n<li>another sublist</li>\n</ul></li>\n</ul>\n",
1120	}
1121	doTestsBlock(t, tests, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
1122}
1123
1124func TestOrderedList_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
1125	var tests = []string{
1126		"1. Hello\n",
1127		"<ol>\n<li>Hello</li>\n</ol>\n",
1128
1129		"1. Yin\n2. Yang\n",
1130		"<ol>\n<li>Yin</li>\n<li>Yang</li>\n</ol>\n",
1131
1132		"1. Ting\n2. Bong\n3. Goo\n",
1133		"<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n",
1134
1135		"1. Yin\n\n2. Yang\n",
1136		"<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n",
1137
1138		"1. Ting\n\n2. Bong\n3. Goo\n",
1139		"<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n",
1140
1141		"1 Hello\n",
1142		"<p>1 Hello</p>\n",
1143
1144		"1.Hello\n",
1145		"<p>1.Hello</p>\n",
1146
1147		"1.  Hello \n",
1148		"<ol>\n<li>Hello</li>\n</ol>\n",
1149
1150		"1.  Hello \n    Next line \n",
1151		"<ol>\n<li>Hello\nNext line</li>\n</ol>\n",
1152
1153		"Paragraph\n1. No linebreak\n",
1154		"<p>Paragraph</p>\n\n<ol>\n<li>No linebreak</li>\n</ol>\n",
1155
1156		"Paragraph\n\n1. Linebreak\n",
1157		"<p>Paragraph</p>\n\n<ol>\n<li>Linebreak</li>\n</ol>\n",
1158
1159		"1.  List\n    1. Nested list\n",
1160		"<ol>\n<li>List\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",
1161
1162		"1.  List\n\n    1. Nested list\n",
1163		"<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",
1164
1165		"1.  List\n    Second line\n\n    1. Nested\n",
1166		"<ol>\n<li><p>List\nSecond line</p>\n\n<ol>\n<li>Nested</li>\n</ol></li>\n</ol>\n",
1167
1168		"1.  List\n    1. Nested\n\n    Continued\n",
1169		"<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested</li>\n</ol>\n\n<p>Continued</p></li>\n</ol>\n",
1170
1171		"1.  List\n   1. shallow indent\n",
1172		"<ol>\n<li>List\n\n<ol>\n<li>shallow indent</li>\n</ol></li>\n</ol>\n",
1173
1174		"1. List\n" +
1175			" 1. shallow indent\n" +
1176			"  2. part of second list\n" +
1177			"   3. still second\n" +
1178			"    4. almost there\n" +
1179			"     1. third level\n",
1180		"<ol>\n" +
1181			"<li>List\n\n" +
1182			"<ol>\n" +
1183			"<li>shallow indent</li>\n" +
1184			"<li>part of second list</li>\n" +
1185			"<li>still second</li>\n" +
1186			"<li>almost there\n\n" +
1187			"<ol>\n" +
1188			"<li>third level</li>\n" +
1189			"</ol></li>\n" +
1190			"</ol></li>\n" +
1191			"</ol>\n",
1192
1193		"1. List\n        extra indent, same paragraph\n",
1194		"<ol>\n<li>List\n    extra indent, same paragraph</li>\n</ol>\n",
1195
1196		"1. List\n\n        code block\n",
1197		"<ol>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ol>\n",
1198
1199		"1. List\n\n          code block with spaces\n",
1200		"<ol>\n<li><p>List</p>\n\n<pre><code>  code block with spaces\n</code></pre></li>\n</ol>\n",
1201
1202		"1. List\n    * Mixted list\n",
1203		"<ol>\n<li>List\n\n<ul>\n<li>Mixted list</li>\n</ul></li>\n</ol>\n",
1204
1205		"1. List\n * Mixed list\n",
1206		"<ol>\n<li>List\n\n<ul>\n<li>Mixed list</li>\n</ul></li>\n</ol>\n",
1207
1208		"* Start with unordered\n 1. Ordered\n",
1209		"<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",
1210
1211		"* Start with unordered\n    1. Ordered\n",
1212		"<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",
1213
1214		"1. numbers\n1. are ignored\n",
1215		"<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n",
1216	}
1217	doTestsBlock(t, tests, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
1218}
1219
1220func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
1221	var tests = []string{
1222		"``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",
1223		"<pre><code class=\"language-go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",
1224
1225		"``` c\n/* special & char < > \" escaping */\n```\n",
1226		"<pre><code class=\"language-c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",
1227
1228		"``` c\nno *inline* processing ~~of text~~\n```\n",
1229		"<pre><code class=\"language-c\">no *inline* processing ~~of text~~\n</code></pre>\n",
1230
1231		"```\nNo language\n```\n",
1232		"<pre><code>No language\n</code></pre>\n",
1233
1234		"``` {ocaml}\nlanguage in braces\n```\n",
1235		"<pre><code class=\"language-ocaml\">language in braces\n</code></pre>\n",
1236
1237		"```    {ocaml}      \nwith extra whitespace\n```\n",
1238		"<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",
1239
1240		"```{   ocaml   }\nwith extra whitespace\n```\n",
1241		"<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",
1242
1243		"~ ~~ java\nWith whitespace\n~~~\n",
1244		"<p>~ ~~ java\nWith whitespace\n~~~</p>\n",
1245
1246		"~~\nonly two\n~~\n",
1247		"<p>~~\nonly two\n~~</p>\n",
1248
1249		"```` python\nextra\n````\n",
1250		"<pre><code class=\"language-python\">extra\n</code></pre>\n",
1251
1252		"~~~ perl\nthree to start, four to end\n~~~~\n",
1253		"<p>~~~ perl\nthree to start, four to end\n~~~~</p>\n",
1254
1255		"~~~~ perl\nfour to start, three to end\n~~~\n",
1256		"<p>~~~~ perl\nfour to start, three to end\n~~~</p>\n",
1257
1258		"~~~ bash\ntildes\n~~~\n",
1259		"<pre><code class=\"language-bash\">tildes\n</code></pre>\n",
1260
1261		"``` lisp\nno ending\n",
1262		"<p>``` lisp\nno ending</p>\n",
1263
1264		"~~~ lisp\nend with language\n~~~ lisp\n",
1265		"<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",
1266
1267		"```\nmismatched begin and end\n~~~\n",
1268		"<p>```\nmismatched begin and end\n~~~</p>\n",
1269
1270		"~~~\nmismatched begin and end\n```\n",
1271		"<p>~~~\nmismatched begin and end\n```</p>\n",
1272
1273		"   ``` oz\nleading spaces\n```\n",
1274		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
1275
1276		"  ``` oz\nleading spaces\n ```\n",
1277		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
1278
1279		" ``` oz\nleading spaces\n  ```\n",
1280		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
1281
1282		"``` oz\nleading spaces\n   ```\n",
1283		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
1284
1285		"    ``` oz\nleading spaces\n    ```\n",
1286		"<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces</p>\n\n<pre><code>```\n</code></pre>\n",
1287	}
1288	doTestsBlock(t, tests, EXTENSION_FENCED_CODE|EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
1289}
1290
1291func TestTitleBlock_EXTENSION_TITLEBLOCK(t *testing.T) {
1292	var tests = []string{
1293		"% Some title\n" +
1294			"% Another title line\n" +
1295			"% Yep, more here too\n",
1296		"<h1 class=\"title\">" +
1297			"Some title\n" +
1298			"Another title line\n" +
1299			"Yep, more here too\n" +
1300			"</h1>",
1301	}
1302
1303	doTestsBlock(t, tests, EXTENSION_TITLEBLOCK)
1304
1305}