all repos — grayfriday @ 195dac9f5b4031be2dfd529114a6191a1b512d31

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