github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/russross/blackfriday/block_test.go (about)

     1  //
     2  // Blackfriday Markdown Processor
     3  // Available at http://yougam/libraries/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  
    14  package blackfriday
    15  
    16  import (
    17  	"strings"
    18  	"testing"
    19  )
    20  
    21  func runMarkdownBlockWithRenderer(input string, extensions int, renderer Renderer) string {
    22  	return string(Markdown([]byte(input), renderer, extensions))
    23  }
    24  
    25  func runMarkdownBlock(input string, extensions int) string {
    26  	htmlFlags := 0
    27  	htmlFlags |= HTML_USE_XHTML
    28  
    29  	renderer := HtmlRenderer(htmlFlags, "", "")
    30  
    31  	return runMarkdownBlockWithRenderer(input, extensions, renderer)
    32  }
    33  
    34  func runnerWithRendererParameters(parameters HtmlRendererParameters) func(string, int) string {
    35  	return func(input string, extensions int) string {
    36  		htmlFlags := 0
    37  		htmlFlags |= HTML_USE_XHTML
    38  
    39  		renderer := HtmlRendererWithParameters(htmlFlags, "", "", parameters)
    40  
    41  		return runMarkdownBlockWithRenderer(input, extensions, renderer)
    42  	}
    43  }
    44  
    45  func doTestsBlock(t *testing.T, tests []string, extensions int) {
    46  	doTestsBlockWithRunner(t, tests, extensions, runMarkdownBlock)
    47  }
    48  
    49  func doTestsBlockWithRunner(t *testing.T, tests []string, extensions int, runner func(string, int) string) {
    50  	// catch and report panics
    51  	var candidate string
    52  	defer func() {
    53  		if err := recover(); err != nil {
    54  			t.Errorf("\npanic while processing [%#v]: %s\n", candidate, err)
    55  		}
    56  	}()
    57  
    58  	for i := 0; i+1 < len(tests); i += 2 {
    59  		input := tests[i]
    60  		candidate = input
    61  		expected := tests[i+1]
    62  		actual := runner(candidate, extensions)
    63  		if actual != expected {
    64  			t.Errorf("\nInput   [%#v]\nExpected[%#v]\nActual  [%#v]",
    65  				candidate, expected, actual)
    66  		}
    67  
    68  		// now test every substring to stress test bounds checking
    69  		if !testing.Short() {
    70  			for start := 0; start < len(input); start++ {
    71  				for end := start + 1; end <= len(input); end++ {
    72  					candidate = input[start:end]
    73  					_ = runMarkdownBlock(candidate, extensions)
    74  				}
    75  			}
    76  		}
    77  	}
    78  }
    79  
    80  func TestPrefixHeaderNoExtensions(t *testing.T) {
    81  	var tests = []string{
    82  		"# Header 1\n",
    83  		"<h1>Header 1</h1>\n",
    84  
    85  		"## Header 2\n",
    86  		"<h2>Header 2</h2>\n",
    87  
    88  		"### Header 3\n",
    89  		"<h3>Header 3</h3>\n",
    90  
    91  		"#### Header 4\n",
    92  		"<h4>Header 4</h4>\n",
    93  
    94  		"##### Header 5\n",
    95  		"<h5>Header 5</h5>\n",
    96  
    97  		"###### Header 6\n",
    98  		"<h6>Header 6</h6>\n",
    99  
   100  		"####### Header 7\n",
   101  		"<h6># Header 7</h6>\n",
   102  
   103  		"#Header 1\n",
   104  		"<h1>Header 1</h1>\n",
   105  
   106  		"##Header 2\n",
   107  		"<h2>Header 2</h2>\n",
   108  
   109  		"###Header 3\n",
   110  		"<h3>Header 3</h3>\n",
   111  
   112  		"####Header 4\n",
   113  		"<h4>Header 4</h4>\n",
   114  
   115  		"#####Header 5\n",
   116  		"<h5>Header 5</h5>\n",
   117  
   118  		"######Header 6\n",
   119  		"<h6>Header 6</h6>\n",
   120  
   121  		"#######Header 7\n",
   122  		"<h6>#Header 7</h6>\n",
   123  
   124  		"Hello\n# Header 1\nGoodbye\n",
   125  		"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",
   126  
   127  		"* List\n# Header\n* List\n",
   128  		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
   129  
   130  		"* List\n#Header\n* List\n",
   131  		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
   132  
   133  		"*   List\n    * Nested list\n    # Nested header\n",
   134  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
   135  			"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
   136  
   137  		"#Header 1 \\#\n",
   138  		"<h1>Header 1 #</h1>\n",
   139  
   140  		"#Header 1 \\# foo\n",
   141  		"<h1>Header 1 # foo</h1>\n",
   142  
   143  		"#Header 1 #\\##\n",
   144  		"<h1>Header 1 ##</h1>\n",
   145  	}
   146  	doTestsBlock(t, tests, 0)
   147  }
   148  
   149  func TestPrefixHeaderSpaceExtension(t *testing.T) {
   150  	var tests = []string{
   151  		"# Header 1\n",
   152  		"<h1>Header 1</h1>\n",
   153  
   154  		"## Header 2\n",
   155  		"<h2>Header 2</h2>\n",
   156  
   157  		"### Header 3\n",
   158  		"<h3>Header 3</h3>\n",
   159  
   160  		"#### Header 4\n",
   161  		"<h4>Header 4</h4>\n",
   162  
   163  		"##### Header 5\n",
   164  		"<h5>Header 5</h5>\n",
   165  
   166  		"###### Header 6\n",
   167  		"<h6>Header 6</h6>\n",
   168  
   169  		"####### Header 7\n",
   170  		"<p>####### Header 7</p>\n",
   171  
   172  		"#Header 1\n",
   173  		"<p>#Header 1</p>\n",
   174  
   175  		"##Header 2\n",
   176  		"<p>##Header 2</p>\n",
   177  
   178  		"###Header 3\n",
   179  		"<p>###Header 3</p>\n",
   180  
   181  		"####Header 4\n",
   182  		"<p>####Header 4</p>\n",
   183  
   184  		"#####Header 5\n",
   185  		"<p>#####Header 5</p>\n",
   186  
   187  		"######Header 6\n",
   188  		"<p>######Header 6</p>\n",
   189  
   190  		"#######Header 7\n",
   191  		"<p>#######Header 7</p>\n",
   192  
   193  		"Hello\n# Header 1\nGoodbye\n",
   194  		"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",
   195  
   196  		"* List\n# Header\n* List\n",
   197  		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
   198  
   199  		"* List\n#Header\n* List\n",
   200  		"<ul>\n<li>List\n#Header</li>\n<li>List</li>\n</ul>\n",
   201  
   202  		"*   List\n    * Nested list\n    # Nested header\n",
   203  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
   204  			"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
   205  	}
   206  	doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS)
   207  }
   208  
   209  func TestPrefixHeaderIdExtension(t *testing.T) {
   210  	var tests = []string{
   211  		"# Header 1 {#someid}\n",
   212  		"<h1 id=\"someid\">Header 1</h1>\n",
   213  
   214  		"# Header 1 {#someid}   \n",
   215  		"<h1 id=\"someid\">Header 1</h1>\n",
   216  
   217  		"# Header 1         {#someid}\n",
   218  		"<h1 id=\"someid\">Header 1</h1>\n",
   219  
   220  		"# Header 1 {#someid\n",
   221  		"<h1>Header 1 {#someid</h1>\n",
   222  
   223  		"# Header 1 {#someid\n",
   224  		"<h1>Header 1 {#someid</h1>\n",
   225  
   226  		"# Header 1 {#someid}}\n",
   227  		"<h1 id=\"someid\">Header 1</h1>\n\n<p>}</p>\n",
   228  
   229  		"## Header 2 {#someid}\n",
   230  		"<h2 id=\"someid\">Header 2</h2>\n",
   231  
   232  		"### Header 3 {#someid}\n",
   233  		"<h3 id=\"someid\">Header 3</h3>\n",
   234  
   235  		"#### Header 4 {#someid}\n",
   236  		"<h4 id=\"someid\">Header 4</h4>\n",
   237  
   238  		"##### Header 5 {#someid}\n",
   239  		"<h5 id=\"someid\">Header 5</h5>\n",
   240  
   241  		"###### Header 6 {#someid}\n",
   242  		"<h6 id=\"someid\">Header 6</h6>\n",
   243  
   244  		"####### Header 7 {#someid}\n",
   245  		"<h6 id=\"someid\"># Header 7</h6>\n",
   246  
   247  		"# Header 1 # {#someid}\n",
   248  		"<h1 id=\"someid\">Header 1</h1>\n",
   249  
   250  		"## Header 2 ## {#someid}\n",
   251  		"<h2 id=\"someid\">Header 2</h2>\n",
   252  
   253  		"Hello\n# Header 1\nGoodbye\n",
   254  		"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",
   255  
   256  		"* List\n# Header {#someid}\n* List\n",
   257  		"<ul>\n<li><p>List</p>\n\n<h1 id=\"someid\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
   258  
   259  		"* List\n#Header {#someid}\n* List\n",
   260  		"<ul>\n<li><p>List</p>\n\n<h1 id=\"someid\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
   261  
   262  		"*   List\n    * Nested list\n    # Nested header {#someid}\n",
   263  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
   264  			"<h1 id=\"someid\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
   265  	}
   266  	doTestsBlock(t, tests, EXTENSION_HEADER_IDS)
   267  }
   268  
   269  func TestPrefixHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {
   270  	var tests = []string{
   271  		"# header 1 {#someid}\n",
   272  		"<h1 id=\"PRE:someid:POST\">header 1</h1>\n",
   273  
   274  		"## header 2 {#someid}\n",
   275  		"<h2 id=\"PRE:someid:POST\">header 2</h2>\n",
   276  
   277  		"### header 3 {#someid}\n",
   278  		"<h3 id=\"PRE:someid:POST\">header 3</h3>\n",
   279  
   280  		"#### header 4 {#someid}\n",
   281  		"<h4 id=\"PRE:someid:POST\">header 4</h4>\n",
   282  
   283  		"##### header 5 {#someid}\n",
   284  		"<h5 id=\"PRE:someid:POST\">header 5</h5>\n",
   285  
   286  		"###### header 6 {#someid}\n",
   287  		"<h6 id=\"PRE:someid:POST\">header 6</h6>\n",
   288  
   289  		"####### header 7 {#someid}\n",
   290  		"<h6 id=\"PRE:someid:POST\"># header 7</h6>\n",
   291  
   292  		"# header 1 # {#someid}\n",
   293  		"<h1 id=\"PRE:someid:POST\">header 1</h1>\n",
   294  
   295  		"## header 2 ## {#someid}\n",
   296  		"<h2 id=\"PRE:someid:POST\">header 2</h2>\n",
   297  
   298  		"* List\n# Header {#someid}\n* List\n",
   299  		"<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",
   300  
   301  		"* List\n#Header {#someid}\n* List\n",
   302  		"<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",
   303  
   304  		"*   List\n    * Nested list\n    # Nested header {#someid}\n",
   305  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
   306  			"<h1 id=\"PRE:someid:POST\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
   307  	}
   308  
   309  	parameters := HtmlRendererParameters{
   310  		HeaderIDPrefix: "PRE:",
   311  		HeaderIDSuffix: ":POST",
   312  	}
   313  
   314  	doTestsBlockWithRunner(t, tests, EXTENSION_HEADER_IDS, runnerWithRendererParameters(parameters))
   315  }
   316  
   317  func TestPrefixAutoHeaderIdExtension(t *testing.T) {
   318  	var tests = []string{
   319  		"# Header 1\n",
   320  		"<h1 id=\"header-1\">Header 1</h1>\n",
   321  
   322  		"# Header 1   \n",
   323  		"<h1 id=\"header-1\">Header 1</h1>\n",
   324  
   325  		"## Header 2\n",
   326  		"<h2 id=\"header-2\">Header 2</h2>\n",
   327  
   328  		"### Header 3\n",
   329  		"<h3 id=\"header-3\">Header 3</h3>\n",
   330  
   331  		"#### Header 4\n",
   332  		"<h4 id=\"header-4\">Header 4</h4>\n",
   333  
   334  		"##### Header 5\n",
   335  		"<h5 id=\"header-5\">Header 5</h5>\n",
   336  
   337  		"###### Header 6\n",
   338  		"<h6 id=\"header-6\">Header 6</h6>\n",
   339  
   340  		"####### Header 7\n",
   341  		"<h6 id=\"header-7\"># Header 7</h6>\n",
   342  
   343  		"Hello\n# Header 1\nGoodbye\n",
   344  		"<p>Hello</p>\n\n<h1 id=\"header-1\">Header 1</h1>\n\n<p>Goodbye</p>\n",
   345  
   346  		"* List\n# Header\n* List\n",
   347  		"<ul>\n<li><p>List</p>\n\n<h1 id=\"header\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
   348  
   349  		"* List\n#Header\n* List\n",
   350  		"<ul>\n<li><p>List</p>\n\n<h1 id=\"header\">Header</h1></li>\n\n<li><p>List</p></li>\n</ul>\n",
   351  
   352  		"*   List\n    * Nested list\n    # Nested header\n",
   353  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
   354  			"<h1 id=\"nested-header\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
   355  
   356  		"# Header\n\n# Header\n",
   357  		"<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n",
   358  
   359  		"# Header 1\n\n# Header 1",
   360  		"<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",
   361  
   362  		"# Header\n\n# Header 1\n\n# Header\n\n# Header",
   363  		"<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",
   364  	}
   365  	doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS)
   366  }
   367  
   368  func TestPrefixAutoHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {
   369  	var tests = []string{
   370  		"# Header 1\n",
   371  		"<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n",
   372  
   373  		"# Header 1   \n",
   374  		"<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n",
   375  
   376  		"## Header 2\n",
   377  		"<h2 id=\"PRE:header-2:POST\">Header 2</h2>\n",
   378  
   379  		"### Header 3\n",
   380  		"<h3 id=\"PRE:header-3:POST\">Header 3</h3>\n",
   381  
   382  		"#### Header 4\n",
   383  		"<h4 id=\"PRE:header-4:POST\">Header 4</h4>\n",
   384  
   385  		"##### Header 5\n",
   386  		"<h5 id=\"PRE:header-5:POST\">Header 5</h5>\n",
   387  
   388  		"###### Header 6\n",
   389  		"<h6 id=\"PRE:header-6:POST\">Header 6</h6>\n",
   390  
   391  		"####### Header 7\n",
   392  		"<h6 id=\"PRE:header-7:POST\"># Header 7</h6>\n",
   393  
   394  		"Hello\n# Header 1\nGoodbye\n",
   395  		"<p>Hello</p>\n\n<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<p>Goodbye</p>\n",
   396  
   397  		"* List\n# Header\n* List\n",
   398  		"<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",
   399  
   400  		"* List\n#Header\n* List\n",
   401  		"<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",
   402  
   403  		"*   List\n    * Nested list\n    # Nested header\n",
   404  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
   405  			"<h1 id=\"PRE:nested-header:POST\">Nested header</h1></li>\n</ul></li>\n</ul>\n",
   406  
   407  		"# Header\n\n# Header\n",
   408  		"<h1 id=\"PRE:header:POST\">Header</h1>\n\n<h1 id=\"PRE:header-1:POST\">Header</h1>\n",
   409  
   410  		"# Header 1\n\n# Header 1",
   411  		"<h1 id=\"PRE:header-1:POST\">Header 1</h1>\n\n<h1 id=\"PRE:header-1-1:POST\">Header 1</h1>\n",
   412  
   413  		"# Header\n\n# Header 1\n\n# Header\n\n# Header",
   414  		"<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",
   415  	}
   416  
   417  	parameters := HtmlRendererParameters{
   418  		HeaderIDPrefix: "PRE:",
   419  		HeaderIDSuffix: ":POST",
   420  	}
   421  
   422  	doTestsBlockWithRunner(t, tests, EXTENSION_AUTO_HEADER_IDS, runnerWithRendererParameters(parameters))
   423  }
   424  
   425  func TestPrefixMultipleHeaderExtensions(t *testing.T) {
   426  	var tests = []string{
   427  		"# Header\n\n# Header {#header}\n\n# Header 1",
   428  		"<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",
   429  	}
   430  	doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS|EXTENSION_HEADER_IDS)
   431  }
   432  
   433  func TestUnderlineHeaders(t *testing.T) {
   434  	var tests = []string{
   435  		"Header 1\n========\n",
   436  		"<h1>Header 1</h1>\n",
   437  
   438  		"Header 2\n--------\n",
   439  		"<h2>Header 2</h2>\n",
   440  
   441  		"A\n=\n",
   442  		"<h1>A</h1>\n",
   443  
   444  		"B\n-\n",
   445  		"<h2>B</h2>\n",
   446  
   447  		"Paragraph\nHeader\n=\n",
   448  		"<p>Paragraph</p>\n\n<h1>Header</h1>\n",
   449  
   450  		"Header\n===\nParagraph\n",
   451  		"<h1>Header</h1>\n\n<p>Paragraph</p>\n",
   452  
   453  		"Header\n===\nAnother header\n---\n",
   454  		"<h1>Header</h1>\n\n<h2>Another header</h2>\n",
   455  
   456  		"   Header\n======\n",
   457  		"<h1>Header</h1>\n",
   458  
   459  		"    Code\n========\n",
   460  		"<pre><code>Code\n</code></pre>\n\n<p>========</p>\n",
   461  
   462  		"Header with *inline*\n=====\n",
   463  		"<h1>Header with <em>inline</em></h1>\n",
   464  
   465  		"*   List\n    * Sublist\n    Not a header\n    ------\n",
   466  		"<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",
   467  
   468  		"Paragraph\n\n\n\n\nHeader\n===\n",
   469  		"<p>Paragraph</p>\n\n<h1>Header</h1>\n",
   470  
   471  		"Trailing space \n====        \n\n",
   472  		"<h1>Trailing space</h1>\n",
   473  
   474  		"Trailing spaces\n====        \n\n",
   475  		"<h1>Trailing spaces</h1>\n",
   476  
   477  		"Double underline\n=====\n=====\n",
   478  		"<h1>Double underline</h1>\n\n<p>=====</p>\n",
   479  	}
   480  	doTestsBlock(t, tests, 0)
   481  }
   482  
   483  func TestUnderlineHeadersAutoIDs(t *testing.T) {
   484  	var tests = []string{
   485  		"Header 1\n========\n",
   486  		"<h1 id=\"header-1\">Header 1</h1>\n",
   487  
   488  		"Header 2\n--------\n",
   489  		"<h2 id=\"header-2\">Header 2</h2>\n",
   490  
   491  		"A\n=\n",
   492  		"<h1 id=\"a\">A</h1>\n",
   493  
   494  		"B\n-\n",
   495  		"<h2 id=\"b\">B</h2>\n",
   496  
   497  		"Paragraph\nHeader\n=\n",
   498  		"<p>Paragraph</p>\n\n<h1 id=\"header\">Header</h1>\n",
   499  
   500  		"Header\n===\nParagraph\n",
   501  		"<h1 id=\"header\">Header</h1>\n\n<p>Paragraph</p>\n",
   502  
   503  		"Header\n===\nAnother header\n---\n",
   504  		"<h1 id=\"header\">Header</h1>\n\n<h2 id=\"another-header\">Another header</h2>\n",
   505  
   506  		"   Header\n======\n",
   507  		"<h1 id=\"header\">Header</h1>\n",
   508  
   509  		"Header with *inline*\n=====\n",
   510  		"<h1 id=\"header-with-inline\">Header with <em>inline</em></h1>\n",
   511  
   512  		"Paragraph\n\n\n\n\nHeader\n===\n",
   513  		"<p>Paragraph</p>\n\n<h1 id=\"header\">Header</h1>\n",
   514  
   515  		"Trailing space \n====        \n\n",
   516  		"<h1 id=\"trailing-space\">Trailing space</h1>\n",
   517  
   518  		"Trailing spaces\n====        \n\n",
   519  		"<h1 id=\"trailing-spaces\">Trailing spaces</h1>\n",
   520  
   521  		"Double underline\n=====\n=====\n",
   522  		"<h1 id=\"double-underline\">Double underline</h1>\n\n<p>=====</p>\n",
   523  
   524  		"Header\n======\n\nHeader\n======\n",
   525  		"<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n",
   526  
   527  		"Header 1\n========\n\nHeader 1\n========\n",
   528  		"<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n",
   529  	}
   530  	doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS)
   531  }
   532  
   533  func TestHorizontalRule(t *testing.T) {
   534  	var tests = []string{
   535  		"-\n",
   536  		"<p>-</p>\n",
   537  
   538  		"--\n",
   539  		"<p>--</p>\n",
   540  
   541  		"---\n",
   542  		"<hr />\n",
   543  
   544  		"----\n",
   545  		"<hr />\n",
   546  
   547  		"*\n",
   548  		"<p>*</p>\n",
   549  
   550  		"**\n",
   551  		"<p>**</p>\n",
   552  
   553  		"***\n",
   554  		"<hr />\n",
   555  
   556  		"****\n",
   557  		"<hr />\n",
   558  
   559  		"_\n",
   560  		"<p>_</p>\n",
   561  
   562  		"__\n",
   563  		"<p>__</p>\n",
   564  
   565  		"___\n",
   566  		"<hr />\n",
   567  
   568  		"____\n",
   569  		"<hr />\n",
   570  
   571  		"-*-\n",
   572  		"<p>-*-</p>\n",
   573  
   574  		"- - -\n",
   575  		"<hr />\n",
   576  
   577  		"* * *\n",
   578  		"<hr />\n",
   579  
   580  		"_ _ _\n",
   581  		"<hr />\n",
   582  
   583  		"-----*\n",
   584  		"<p>-----*</p>\n",
   585  
   586  		"   ------   \n",
   587  		"<hr />\n",
   588  
   589  		"Hello\n***\n",
   590  		"<p>Hello</p>\n\n<hr />\n",
   591  
   592  		"---\n***\n___\n",
   593  		"<hr />\n\n<hr />\n\n<hr />\n",
   594  	}
   595  	doTestsBlock(t, tests, 0)
   596  }
   597  
   598  func TestUnorderedList(t *testing.T) {
   599  	var tests = []string{
   600  		"* Hello\n",
   601  		"<ul>\n<li>Hello</li>\n</ul>\n",
   602  
   603  		"* Yin\n* Yang\n",
   604  		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
   605  
   606  		"* Ting\n* Bong\n* Goo\n",
   607  		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
   608  
   609  		"* Yin\n\n* Yang\n",
   610  		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
   611  
   612  		"* Ting\n\n* Bong\n* Goo\n",
   613  		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
   614  
   615  		"+ Hello\n",
   616  		"<ul>\n<li>Hello</li>\n</ul>\n",
   617  
   618  		"+ Yin\n+ Yang\n",
   619  		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
   620  
   621  		"+ Ting\n+ Bong\n+ Goo\n",
   622  		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
   623  
   624  		"+ Yin\n\n+ Yang\n",
   625  		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
   626  
   627  		"+ Ting\n\n+ Bong\n+ Goo\n",
   628  		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
   629  
   630  		"- Hello\n",
   631  		"<ul>\n<li>Hello</li>\n</ul>\n",
   632  
   633  		"- Yin\n- Yang\n",
   634  		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
   635  
   636  		"- Ting\n- Bong\n- Goo\n",
   637  		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
   638  
   639  		"- Yin\n\n- Yang\n",
   640  		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
   641  
   642  		"- Ting\n\n- Bong\n- Goo\n",
   643  		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
   644  
   645  		"*Hello\n",
   646  		"<p>*Hello</p>\n",
   647  
   648  		"*   Hello \n",
   649  		"<ul>\n<li>Hello</li>\n</ul>\n",
   650  
   651  		"*   Hello \n    Next line \n",
   652  		"<ul>\n<li>Hello\nNext line</li>\n</ul>\n",
   653  
   654  		"Paragraph\n* No linebreak\n",
   655  		"<p>Paragraph\n* No linebreak</p>\n",
   656  
   657  		"Paragraph\n\n* Linebreak\n",
   658  		"<p>Paragraph</p>\n\n<ul>\n<li>Linebreak</li>\n</ul>\n",
   659  
   660  		"*   List\n\n1. Spacer Mixed listing\n",
   661  		"<ul>\n<li>List</li>\n</ul>\n\n<ol>\n<li>Spacer Mixed listing</li>\n</ol>\n",
   662  
   663  		"*   List\n    * Nested list\n",
   664  		"<ul>\n<li>List\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",
   665  
   666  		"*   List\n\n    * Nested list\n",
   667  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",
   668  
   669  		"*   List\n    Second line\n\n    + Nested\n",
   670  		"<ul>\n<li><p>List\nSecond line</p>\n\n<ul>\n<li>Nested</li>\n</ul></li>\n</ul>\n",
   671  
   672  		"*   List\n    + Nested\n\n    Continued\n",
   673  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested</li>\n</ul>\n\n<p>Continued</p></li>\n</ul>\n",
   674  
   675  		"*   List\n   * shallow indent\n",
   676  		"<ul>\n<li>List\n\n<ul>\n<li>shallow indent</li>\n</ul></li>\n</ul>\n",
   677  
   678  		"* List\n" +
   679  			" * shallow indent\n" +
   680  			"  * part of second list\n" +
   681  			"   * still second\n" +
   682  			"    * almost there\n" +
   683  			"     * third level\n",
   684  		"<ul>\n" +
   685  			"<li>List\n\n" +
   686  			"<ul>\n" +
   687  			"<li>shallow indent</li>\n" +
   688  			"<li>part of second list</li>\n" +
   689  			"<li>still second</li>\n" +
   690  			"<li>almost there\n\n" +
   691  			"<ul>\n" +
   692  			"<li>third level</li>\n" +
   693  			"</ul></li>\n" +
   694  			"</ul></li>\n" +
   695  			"</ul>\n",
   696  
   697  		"* List\n        extra indent, same paragraph\n",
   698  		"<ul>\n<li>List\n    extra indent, same paragraph</li>\n</ul>\n",
   699  
   700  		"* List\n\n        code block\n",
   701  		"<ul>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ul>\n",
   702  
   703  		"* List\n\n          code block with spaces\n",
   704  		"<ul>\n<li><p>List</p>\n\n<pre><code>  code block with spaces\n</code></pre></li>\n</ul>\n",
   705  
   706  		"* List\n\n    * sublist\n\n    normal text\n\n    * another sublist\n",
   707  		"<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",
   708  
   709  		`* Foo
   710  
   711          bar
   712  
   713          qux
   714  `,
   715  		`<ul>
   716  <li><p>Foo</p>
   717  
   718  <pre><code>bar
   719  
   720  qux
   721  </code></pre></li>
   722  </ul>
   723  `,
   724  	}
   725  	doTestsBlock(t, tests, 0)
   726  }
   727  
   728  func TestFencedCodeBlockWithinList(t *testing.T) {
   729  	doTestsBlock(t, []string{
   730  		"* Foo\n\n    ```\n    bar\n\n    qux\n    ```\n",
   731  		`<ul>
   732  <li><p>Foo</p>
   733  
   734  <pre><code>bar
   735  
   736  qux
   737  </code></pre></li>
   738  </ul>
   739  `,
   740  	}, EXTENSION_FENCED_CODE)
   741  }
   742  
   743  func TestOrderedList(t *testing.T) {
   744  	var tests = []string{
   745  		"1. Hello\n",
   746  		"<ol>\n<li>Hello</li>\n</ol>\n",
   747  
   748  		"1. Yin\n2. Yang\n",
   749  		"<ol>\n<li>Yin</li>\n<li>Yang</li>\n</ol>\n",
   750  
   751  		"1. Ting\n2. Bong\n3. Goo\n",
   752  		"<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n",
   753  
   754  		"1. Yin\n\n2. Yang\n",
   755  		"<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n",
   756  
   757  		"1. Ting\n\n2. Bong\n3. Goo\n",
   758  		"<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n",
   759  
   760  		"1 Hello\n",
   761  		"<p>1 Hello</p>\n",
   762  
   763  		"1.Hello\n",
   764  		"<p>1.Hello</p>\n",
   765  
   766  		"1.  Hello \n",
   767  		"<ol>\n<li>Hello</li>\n</ol>\n",
   768  
   769  		"1.  Hello \n    Next line \n",
   770  		"<ol>\n<li>Hello\nNext line</li>\n</ol>\n",
   771  
   772  		"Paragraph\n1. No linebreak\n",
   773  		"<p>Paragraph\n1. No linebreak</p>\n",
   774  
   775  		"Paragraph\n\n1. Linebreak\n",
   776  		"<p>Paragraph</p>\n\n<ol>\n<li>Linebreak</li>\n</ol>\n",
   777  
   778  		"1.  List\n    1. Nested list\n",
   779  		"<ol>\n<li>List\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",
   780  
   781  		"1.  List\n\n    1. Nested list\n",
   782  		"<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",
   783  
   784  		"1.  List\n    Second line\n\n    1. Nested\n",
   785  		"<ol>\n<li><p>List\nSecond line</p>\n\n<ol>\n<li>Nested</li>\n</ol></li>\n</ol>\n",
   786  
   787  		"1.  List\n    1. Nested\n\n    Continued\n",
   788  		"<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested</li>\n</ol>\n\n<p>Continued</p></li>\n</ol>\n",
   789  
   790  		"1.  List\n   1. shallow indent\n",
   791  		"<ol>\n<li>List\n\n<ol>\n<li>shallow indent</li>\n</ol></li>\n</ol>\n",
   792  
   793  		"1. List\n" +
   794  			" 1. shallow indent\n" +
   795  			"  2. part of second list\n" +
   796  			"   3. still second\n" +
   797  			"    4. almost there\n" +
   798  			"     1. third level\n",
   799  		"<ol>\n" +
   800  			"<li>List\n\n" +
   801  			"<ol>\n" +
   802  			"<li>shallow indent</li>\n" +
   803  			"<li>part of second list</li>\n" +
   804  			"<li>still second</li>\n" +
   805  			"<li>almost there\n\n" +
   806  			"<ol>\n" +
   807  			"<li>third level</li>\n" +
   808  			"</ol></li>\n" +
   809  			"</ol></li>\n" +
   810  			"</ol>\n",
   811  
   812  		"1. List\n        extra indent, same paragraph\n",
   813  		"<ol>\n<li>List\n    extra indent, same paragraph</li>\n</ol>\n",
   814  
   815  		"1. List\n\n        code block\n",
   816  		"<ol>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ol>\n",
   817  
   818  		"1. List\n\n          code block with spaces\n",
   819  		"<ol>\n<li><p>List</p>\n\n<pre><code>  code block with spaces\n</code></pre></li>\n</ol>\n",
   820  
   821  		"1. List\n\n* Spacer Mixed listing\n",
   822  		"<ol>\n<li>List</li>\n</ol>\n\n<ul>\n<li>Spacer Mixed listing</li>\n</ul>\n",
   823  
   824  		"1. List\n* Mixed listing\n",
   825  		"<ol>\n<li>List</li>\n<li>Mixed listing</li>\n</ol>\n",
   826  
   827  		"1. List\n    * Mixted list\n",
   828  		"<ol>\n<li>List\n\n<ul>\n<li>Mixted list</li>\n</ul></li>\n</ol>\n",
   829  
   830  		"1. List\n * Mixed list\n",
   831  		"<ol>\n<li>List\n\n<ul>\n<li>Mixed list</li>\n</ul></li>\n</ol>\n",
   832  
   833  		"* Start with unordered\n 1. Ordered\n",
   834  		"<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",
   835  
   836  		"* Start with unordered\n    1. Ordered\n",
   837  		"<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",
   838  
   839  		"1. numbers\n1. are ignored\n",
   840  		"<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n",
   841  
   842  		`1. Foo
   843  
   844          bar
   845  
   846  
   847  
   848          qux
   849  `,
   850  		`<ol>
   851  <li><p>Foo</p>
   852  
   853  <pre><code>bar
   854  
   855  
   856  
   857  qux
   858  </code></pre></li>
   859  </ol>
   860  `,
   861  	}
   862  	doTestsBlock(t, tests, 0)
   863  }
   864  
   865  func TestDefinitionList(t *testing.T) {
   866  	var tests = []string{
   867  		"Term 1\n:   Definition a\n",
   868  		"<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n</dl>\n",
   869  
   870  		"Term 1\n:   Definition a \n",
   871  		"<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n</dl>\n",
   872  
   873  		"Term 1\n:   Definition a\n:   Definition b\n",
   874  		"<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n<dd>Definition b</dd>\n</dl>\n",
   875  
   876  		"Term 1\n:   Definition a\n\nTerm 2\n:   Definition b\n",
   877  		"<dl>\n" +
   878  			"<dt>Term 1</dt>\n" +
   879  			"<dd>Definition a</dd>\n" +
   880  			"<dt>Term 2</dt>\n" +
   881  			"<dd>Definition b</dd>\n" +
   882  			"</dl>\n",
   883  
   884  		"Term 1\n:   Definition a\n\nTerm 2\n:   Definition b\n\nTerm 3\n:   Definition c\n",
   885  		"<dl>\n" +
   886  			"<dt>Term 1</dt>\n" +
   887  			"<dd>Definition a</dd>\n" +
   888  			"<dt>Term 2</dt>\n" +
   889  			"<dd>Definition b</dd>\n" +
   890  			"<dt>Term 3</dt>\n" +
   891  			"<dd>Definition c</dd>\n" +
   892  			"</dl>\n",
   893  
   894  		"Term 1\n:   Definition a\n:   Definition b\n\nTerm 2\n:   Definition c\n",
   895  		"<dl>\n" +
   896  			"<dt>Term 1</dt>\n" +
   897  			"<dd>Definition a</dd>\n" +
   898  			"<dd>Definition b</dd>\n" +
   899  			"<dt>Term 2</dt>\n" +
   900  			"<dd>Definition c</dd>\n" +
   901  			"</dl>\n",
   902  
   903  		"Term 1\n\n:   Definition a\n\nTerm 2\n\n:   Definition b\n",
   904  		"<dl>\n" +
   905  			"<dt>Term 1</dt>\n" +
   906  			"<dd><p>Definition a</p></dd>\n" +
   907  			"<dt>Term 2</dt>\n" +
   908  			"<dd><p>Definition b</p></dd>\n" +
   909  			"</dl>\n",
   910  
   911  		"Term 1\n\n:   Definition a\n\n:   Definition b\n\nTerm 2\n\n:   Definition c\n",
   912  		"<dl>\n" +
   913  			"<dt>Term 1</dt>\n" +
   914  			"<dd><p>Definition a</p></dd>\n" +
   915  			"<dd><p>Definition b</p></dd>\n" +
   916  			"<dt>Term 2</dt>\n" +
   917  			"<dd><p>Definition c</p></dd>\n" +
   918  			"</dl>\n",
   919  
   920  		"Term 1\n:   Definition a\nNext line\n",
   921  		"<dl>\n<dt>Term 1</dt>\n<dd>Definition a\nNext line</dd>\n</dl>\n",
   922  
   923  		"Term 1\n:   Definition a\n  Next line\n",
   924  		"<dl>\n<dt>Term 1</dt>\n<dd>Definition a\nNext line</dd>\n</dl>\n",
   925  
   926  		"Term 1\n:   Definition a \n  Next line \n",
   927  		"<dl>\n<dt>Term 1</dt>\n<dd>Definition a\nNext line</dd>\n</dl>\n",
   928  
   929  		"Term 1\n:   Definition a\nNext line\n\nTerm 2\n:   Definition b",
   930  		"<dl>\n" +
   931  			"<dt>Term 1</dt>\n" +
   932  			"<dd>Definition a\nNext line</dd>\n" +
   933  			"<dt>Term 2</dt>\n" +
   934  			"<dd>Definition b</dd>\n" +
   935  			"</dl>\n",
   936  
   937  		"Term 1\n: Definition a\n",
   938  		"<dl>\n<dt>Term 1</dt>\n<dd>Definition a</dd>\n</dl>\n",
   939  
   940  		"Term 1\n:Definition a\n",
   941  		"<p>Term 1\n:Definition a</p>\n",
   942  
   943  		"Term 1\n\n:   Definition a\n\nTerm 2\n\n:   Definition b\n\nText 1",
   944  		"<dl>\n" +
   945  			"<dt>Term 1</dt>\n" +
   946  			"<dd><p>Definition a</p></dd>\n" +
   947  			"<dt>Term 2</dt>\n" +
   948  			"<dd><p>Definition b</p></dd>\n" +
   949  			"</dl>\n" +
   950  			"\n<p>Text 1</p>\n",
   951  
   952  		"Term 1\n\n:   Definition a\n\nText 1\n\nTerm 2\n\n:   Definition b\n\nText 2",
   953  		"<dl>\n" +
   954  			"<dt>Term 1</dt>\n" +
   955  			"<dd><p>Definition a</p></dd>\n" +
   956  			"</dl>\n" +
   957  			"\n<p>Text 1</p>\n" +
   958  			"\n<dl>\n" +
   959  			"<dt>Term 2</dt>\n" +
   960  			"<dd><p>Definition b</p></dd>\n" +
   961  			"</dl>\n" +
   962  			"\n<p>Text 2</p>\n",
   963  
   964  		"Term 1\n:   Definition a\n\n    Text 1\n\n    1. First\n    2. Second",
   965  		"<dl>\n" +
   966  			"<dt>Term 1</dt>\n" +
   967  			"<dd><p>Definition a</p>\n\n" +
   968  			"<p>Text 1</p>\n\n" +
   969  			"<ol>\n<li>First</li>\n<li>Second</li>\n</ol></dd>\n" +
   970  			"</dl>\n",
   971  	}
   972  	doTestsBlock(t, tests, EXTENSION_DEFINITION_LISTS)
   973  }
   974  
   975  func TestPreformattedHtml(t *testing.T) {
   976  	var tests = []string{
   977  		"<div></div>\n",
   978  		"<div></div>\n",
   979  
   980  		"<div>\n</div>\n",
   981  		"<div>\n</div>\n",
   982  
   983  		"<div>\n</div>\nParagraph\n",
   984  		"<p><div>\n</div>\nParagraph</p>\n",
   985  
   986  		"<div class=\"foo\">\n</div>\n",
   987  		"<div class=\"foo\">\n</div>\n",
   988  
   989  		"<div>\nAnything here\n</div>\n",
   990  		"<div>\nAnything here\n</div>\n",
   991  
   992  		"<div>\n  Anything here\n</div>\n",
   993  		"<div>\n  Anything here\n</div>\n",
   994  
   995  		"<div>\nAnything here\n  </div>\n",
   996  		"<div>\nAnything here\n  </div>\n",
   997  
   998  		"<div>\nThis is *not* &proceessed\n</div>\n",
   999  		"<div>\nThis is *not* &proceessed\n</div>\n",
  1000  
  1001  		"<faketag>\n  Something\n</faketag>\n",
  1002  		"<p><faketag>\n  Something\n</faketag></p>\n",
  1003  
  1004  		"<div>\n  Something here\n</divv>\n",
  1005  		"<p><div>\n  Something here\n</divv></p>\n",
  1006  
  1007  		"Paragraph\n<div>\nHere? >&<\n</div>\n",
  1008  		"<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div></p>\n",
  1009  
  1010  		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n",
  1011  		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n",
  1012  
  1013  		"Paragraph\n<div>\nHere? >&<\n</div>\nAnd here?\n",
  1014  		"<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div>\nAnd here?</p>\n",
  1015  
  1016  		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\nAnd here?\n",
  1017  		"<p>Paragraph</p>\n\n<p><div>\nHow about here? &gt;&amp;&lt;\n</div>\nAnd here?</p>\n",
  1018  
  1019  		"Paragraph\n<div>\nHere? >&<\n</div>\n\nAnd here?\n",
  1020  		"<p>Paragraph\n<div>\nHere? &gt;&amp;&lt;\n</div></p>\n\n<p>And here?</p>\n",
  1021  
  1022  		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n",
  1023  		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",
  1024  	}
  1025  	doTestsBlock(t, tests, 0)
  1026  }
  1027  
  1028  func TestPreformattedHtmlLax(t *testing.T) {
  1029  	var tests = []string{
  1030  		"Paragraph\n<div>\nHere? >&<\n</div>\n",
  1031  		"<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n",
  1032  
  1033  		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n",
  1034  		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n",
  1035  
  1036  		"Paragraph\n<div>\nHere? >&<\n</div>\nAnd here?\n",
  1037  		"<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n\n<p>And here?</p>\n",
  1038  
  1039  		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\nAnd here?\n",
  1040  		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",
  1041  
  1042  		"Paragraph\n<div>\nHere? >&<\n</div>\n\nAnd here?\n",
  1043  		"<p>Paragraph</p>\n\n<div>\nHere? >&<\n</div>\n\n<p>And here?</p>\n",
  1044  
  1045  		"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n",
  1046  		"<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n",
  1047  	}
  1048  	doTestsBlock(t, tests, EXTENSION_LAX_HTML_BLOCKS)
  1049  }
  1050  
  1051  func TestFencedCodeBlock(t *testing.T) {
  1052  	var tests = []string{
  1053  		"``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",
  1054  		"<pre><code class=\"language-go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",
  1055  
  1056  		"``` c\n/* special & char < > \" escaping */\n```\n",
  1057  		"<pre><code class=\"language-c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",
  1058  
  1059  		"``` c\nno *inline* processing ~~of text~~\n```\n",
  1060  		"<pre><code class=\"language-c\">no *inline* processing ~~of text~~\n</code></pre>\n",
  1061  
  1062  		"```\nNo language\n```\n",
  1063  		"<pre><code>No language\n</code></pre>\n",
  1064  
  1065  		"``` {ocaml}\nlanguage in braces\n```\n",
  1066  		"<pre><code class=\"language-ocaml\">language in braces\n</code></pre>\n",
  1067  
  1068  		"```    {ocaml}      \nwith extra whitespace\n```\n",
  1069  		"<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",
  1070  
  1071  		"```{   ocaml   }\nwith extra whitespace\n```\n",
  1072  		"<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",
  1073  
  1074  		"~ ~~ java\nWith whitespace\n~~~\n",
  1075  		"<p>~ ~~ java\nWith whitespace\n~~~</p>\n",
  1076  
  1077  		"~~\nonly two\n~~\n",
  1078  		"<p>~~\nonly two\n~~</p>\n",
  1079  
  1080  		"```` python\nextra\n````\n",
  1081  		"<pre><code class=\"language-python\">extra\n</code></pre>\n",
  1082  
  1083  		"~~~ perl\nthree to start, four to end\n~~~~\n",
  1084  		"<p>~~~ perl\nthree to start, four to end\n~~~~</p>\n",
  1085  
  1086  		"~~~~ perl\nfour to start, three to end\n~~~\n",
  1087  		"<p>~~~~ perl\nfour to start, three to end\n~~~</p>\n",
  1088  
  1089  		"~~~ bash\ntildes\n~~~\n",
  1090  		"<pre><code class=\"language-bash\">tildes\n</code></pre>\n",
  1091  
  1092  		"``` lisp\nno ending\n",
  1093  		"<p>``` lisp\nno ending</p>\n",
  1094  
  1095  		"~~~ lisp\nend with language\n~~~ lisp\n",
  1096  		"<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",
  1097  
  1098  		"```\nmismatched begin and end\n~~~\n",
  1099  		"<p>```\nmismatched begin and end\n~~~</p>\n",
  1100  
  1101  		"~~~\nmismatched begin and end\n```\n",
  1102  		"<p>~~~\nmismatched begin and end\n```</p>\n",
  1103  
  1104  		"   ``` oz\nleading spaces\n```\n",
  1105  		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
  1106  
  1107  		"  ``` oz\nleading spaces\n ```\n",
  1108  		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
  1109  
  1110  		" ``` oz\nleading spaces\n  ```\n",
  1111  		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
  1112  
  1113  		"``` oz\nleading spaces\n   ```\n",
  1114  		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
  1115  
  1116  		"    ``` oz\nleading spaces\n    ```\n",
  1117  		"<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces\n    ```</p>\n",
  1118  
  1119  		"Bla bla\n\n``` oz\ncode blocks breakup paragraphs\n```\n\nBla Bla\n",
  1120  		"<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",
  1121  
  1122  		"Some text before a fenced code block\n``` oz\ncode blocks breakup paragraphs\n```\nAnd some text after a fenced code block",
  1123  		"<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",
  1124  
  1125  		"`",
  1126  		"<p>`</p>\n",
  1127  
  1128  		"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",
  1129  		"<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",
  1130  
  1131  		"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",
  1132  		"<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",
  1133  	}
  1134  	doTestsBlock(t, tests, EXTENSION_FENCED_CODE)
  1135  }
  1136  
  1137  func TestFencedCodeInsideBlockquotes(t *testing.T) {
  1138  	cat := func(s ...string) string { return strings.Join(s, "\n") }
  1139  	var tests = []string{
  1140  		cat("> ```go",
  1141  			"package moo",
  1142  			"",
  1143  			"```",
  1144  			""),
  1145  		`<blockquote>
  1146  <pre><code class="language-go">package moo
  1147  
  1148  </code></pre>
  1149  </blockquote>
  1150  `,
  1151  		// -------------------------------------------
  1152  		cat("> foo",
  1153  			"> ",
  1154  			"> ```go",
  1155  			"package moo",
  1156  			"```",
  1157  			"> ",
  1158  			"> goo.",
  1159  			""),
  1160  		`<blockquote>
  1161  <p>foo</p>
  1162  
  1163  <pre><code class="language-go">package moo
  1164  </code></pre>
  1165  
  1166  <p>goo.</p>
  1167  </blockquote>
  1168  `,
  1169  		// -------------------------------------------
  1170  		cat("> foo",
  1171  			"> ",
  1172  			"> quote",
  1173  			"continues",
  1174  			"```",
  1175  			""),
  1176  		`<blockquote>
  1177  <p>foo</p>
  1178  
  1179  <p>quote
  1180  continues
  1181  ` + "```" + `</p>
  1182  </blockquote>
  1183  `,
  1184  		// -------------------------------------------
  1185  		cat("> foo",
  1186  			"> ",
  1187  			"> ```go",
  1188  			"package moo",
  1189  			"```",
  1190  			"> ",
  1191  			"> goo.",
  1192  			"> ",
  1193  			"> ```go",
  1194  			"package zoo",
  1195  			"```",
  1196  			"> ",
  1197  			"> woo.",
  1198  			""),
  1199  		`<blockquote>
  1200  <p>foo</p>
  1201  
  1202  <pre><code class="language-go">package moo
  1203  </code></pre>
  1204  
  1205  <p>goo.</p>
  1206  
  1207  <pre><code class="language-go">package zoo
  1208  </code></pre>
  1209  
  1210  <p>woo.</p>
  1211  </blockquote>
  1212  `,
  1213  	}
  1214  
  1215  	// These 2 alternative forms of blockquoted fenced code blocks should produce same output.
  1216  	forms := [2]string{
  1217  		cat("> plain quoted text",
  1218  			"> ```fenced",
  1219  			"code",
  1220  			" with leading single space correctly preserved",
  1221  			"okay",
  1222  			"```",
  1223  			"> rest of quoted text"),
  1224  		cat("> plain quoted text",
  1225  			"> ```fenced",
  1226  			"> code",
  1227  			">  with leading single space correctly preserved",
  1228  			"> okay",
  1229  			"> ```",
  1230  			"> rest of quoted text"),
  1231  	}
  1232  	want := `<blockquote>
  1233  <p>plain quoted text</p>
  1234  
  1235  <pre><code class="language-fenced">code
  1236   with leading single space correctly preserved
  1237  okay
  1238  </code></pre>
  1239  
  1240  <p>rest of quoted text</p>
  1241  </blockquote>
  1242  `
  1243  	tests = append(tests, forms[0], want)
  1244  	tests = append(tests, forms[1], want)
  1245  
  1246  	doTestsBlock(t, tests, EXTENSION_FENCED_CODE)
  1247  }
  1248  
  1249  func TestTable(t *testing.T) {
  1250  	var tests = []string{
  1251  		"a | b\n---|---\nc | d\n",
  1252  		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n</tr>\n</thead>\n\n" +
  1253  			"<tbody>\n<tr>\n<td>c</td>\n<td>d</td>\n</tr>\n</tbody>\n</table>\n",
  1254  
  1255  		"a | b\n---|--\nc | d\n",
  1256  		"<p>a | b\n---|--\nc | d</p>\n",
  1257  
  1258  		"|a|b|c|d|\n|----|----|----|---|\n|e|f|g|h|\n",
  1259  		"<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" +
  1260  			"<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",
  1261  
  1262  		"*a*|__b__|[c](C)|d\n---|---|---|---\ne|f|g|h\n",
  1263  		"<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" +
  1264  			"<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",
  1265  
  1266  		"a|b|c\n---|---|---\nd|e|f\ng|h\ni|j|k|l|m\nn|o|p\n",
  1267  		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" +
  1268  			"<tbody>\n<tr>\n<td>d</td>\n<td>e</td>\n<td>f</td>\n</tr>\n\n" +
  1269  			"<tr>\n<td>g</td>\n<td>h</td>\n<td></td>\n</tr>\n\n" +
  1270  			"<tr>\n<td>i</td>\n<td>j</td>\n<td>k</td>\n</tr>\n\n" +
  1271  			"<tr>\n<td>n</td>\n<td>o</td>\n<td>p</td>\n</tr>\n</tbody>\n</table>\n",
  1272  
  1273  		"a|b|c\n---|---|---\n*d*|__e__|f\n",
  1274  		"<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n\n" +
  1275  			"<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",
  1276  
  1277  		"a|b|c|d\n:--|--:|:-:|---\ne|f|g|h\n",
  1278  		"<table>\n<thead>\n<tr>\n<th align=\"left\">a</th>\n<th align=\"right\">b</th>\n" +
  1279  			"<th align=\"center\">c</th>\n<th>d</th>\n</tr>\n</thead>\n\n" +
  1280  			"<tbody>\n<tr>\n<td align=\"left\">e</td>\n<td align=\"right\">f</td>\n" +
  1281  			"<td align=\"center\">g</td>\n<td>h</td>\n</tr>\n</tbody>\n</table>\n",
  1282  
  1283  		"a|b|c\n---|---|---\n",
  1284  		"<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",
  1285  
  1286  		"a| b|c | d | e\n---|---|---|---|---\nf| g|h | i |j\n",
  1287  		"<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" +
  1288  			"<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",
  1289  
  1290  		"a|b\\|c|d\n---|---|---\nf|g\\|h|i\n",
  1291  		"<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",
  1292  	}
  1293  	doTestsBlock(t, tests, EXTENSION_TABLES)
  1294  }
  1295  
  1296  func TestUnorderedListWith_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
  1297  	var tests = []string{
  1298  		"* Hello\n",
  1299  		"<ul>\n<li>Hello</li>\n</ul>\n",
  1300  
  1301  		"* Yin\n* Yang\n",
  1302  		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
  1303  
  1304  		"* Ting\n* Bong\n* Goo\n",
  1305  		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
  1306  
  1307  		"* Yin\n\n* Yang\n",
  1308  		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
  1309  
  1310  		"* Ting\n\n* Bong\n* Goo\n",
  1311  		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
  1312  
  1313  		"+ Hello\n",
  1314  		"<ul>\n<li>Hello</li>\n</ul>\n",
  1315  
  1316  		"+ Yin\n+ Yang\n",
  1317  		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
  1318  
  1319  		"+ Ting\n+ Bong\n+ Goo\n",
  1320  		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
  1321  
  1322  		"+ Yin\n\n+ Yang\n",
  1323  		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
  1324  
  1325  		"+ Ting\n\n+ Bong\n+ Goo\n",
  1326  		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
  1327  
  1328  		"- Hello\n",
  1329  		"<ul>\n<li>Hello</li>\n</ul>\n",
  1330  
  1331  		"- Yin\n- Yang\n",
  1332  		"<ul>\n<li>Yin</li>\n<li>Yang</li>\n</ul>\n",
  1333  
  1334  		"- Ting\n- Bong\n- Goo\n",
  1335  		"<ul>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ul>\n",
  1336  
  1337  		"- Yin\n\n- Yang\n",
  1338  		"<ul>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ul>\n",
  1339  
  1340  		"- Ting\n\n- Bong\n- Goo\n",
  1341  		"<ul>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ul>\n",
  1342  
  1343  		"*Hello\n",
  1344  		"<p>*Hello</p>\n",
  1345  
  1346  		"*   Hello \n",
  1347  		"<ul>\n<li>Hello</li>\n</ul>\n",
  1348  
  1349  		"*   Hello \n    Next line \n",
  1350  		"<ul>\n<li>Hello\nNext line</li>\n</ul>\n",
  1351  
  1352  		"Paragraph\n* No linebreak\n",
  1353  		"<p>Paragraph</p>\n\n<ul>\n<li>No linebreak</li>\n</ul>\n",
  1354  
  1355  		"Paragraph\n\n* Linebreak\n",
  1356  		"<p>Paragraph</p>\n\n<ul>\n<li>Linebreak</li>\n</ul>\n",
  1357  
  1358  		"*   List\n    * Nested list\n",
  1359  		"<ul>\n<li>List\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",
  1360  
  1361  		"*   List\n\n    * Nested list\n",
  1362  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested list</li>\n</ul></li>\n</ul>\n",
  1363  
  1364  		"*   List\n    Second line\n\n    + Nested\n",
  1365  		"<ul>\n<li><p>List\nSecond line</p>\n\n<ul>\n<li>Nested</li>\n</ul></li>\n</ul>\n",
  1366  
  1367  		"*   List\n    + Nested\n\n    Continued\n",
  1368  		"<ul>\n<li><p>List</p>\n\n<ul>\n<li>Nested</li>\n</ul>\n\n<p>Continued</p></li>\n</ul>\n",
  1369  
  1370  		"*   List\n   * shallow indent\n",
  1371  		"<ul>\n<li>List\n\n<ul>\n<li>shallow indent</li>\n</ul></li>\n</ul>\n",
  1372  
  1373  		"* List\n" +
  1374  			" * shallow indent\n" +
  1375  			"  * part of second list\n" +
  1376  			"   * still second\n" +
  1377  			"    * almost there\n" +
  1378  			"     * third level\n",
  1379  		"<ul>\n" +
  1380  			"<li>List\n\n" +
  1381  			"<ul>\n" +
  1382  			"<li>shallow indent</li>\n" +
  1383  			"<li>part of second list</li>\n" +
  1384  			"<li>still second</li>\n" +
  1385  			"<li>almost there\n\n" +
  1386  			"<ul>\n" +
  1387  			"<li>third level</li>\n" +
  1388  			"</ul></li>\n" +
  1389  			"</ul></li>\n" +
  1390  			"</ul>\n",
  1391  
  1392  		"* List\n        extra indent, same paragraph\n",
  1393  		"<ul>\n<li>List\n    extra indent, same paragraph</li>\n</ul>\n",
  1394  
  1395  		"* List\n\n        code block\n",
  1396  		"<ul>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ul>\n",
  1397  
  1398  		"* List\n\n          code block with spaces\n",
  1399  		"<ul>\n<li><p>List</p>\n\n<pre><code>  code block with spaces\n</code></pre></li>\n</ul>\n",
  1400  
  1401  		"* List\n\n    * sublist\n\n    normal text\n\n    * another sublist\n",
  1402  		"<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",
  1403  	}
  1404  	doTestsBlock(t, tests, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
  1405  }
  1406  
  1407  func TestOrderedList_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
  1408  	var tests = []string{
  1409  		"1. Hello\n",
  1410  		"<ol>\n<li>Hello</li>\n</ol>\n",
  1411  
  1412  		"1. Yin\n2. Yang\n",
  1413  		"<ol>\n<li>Yin</li>\n<li>Yang</li>\n</ol>\n",
  1414  
  1415  		"1. Ting\n2. Bong\n3. Goo\n",
  1416  		"<ol>\n<li>Ting</li>\n<li>Bong</li>\n<li>Goo</li>\n</ol>\n",
  1417  
  1418  		"1. Yin\n\n2. Yang\n",
  1419  		"<ol>\n<li><p>Yin</p></li>\n\n<li><p>Yang</p></li>\n</ol>\n",
  1420  
  1421  		"1. Ting\n\n2. Bong\n3. Goo\n",
  1422  		"<ol>\n<li><p>Ting</p></li>\n\n<li><p>Bong</p></li>\n\n<li><p>Goo</p></li>\n</ol>\n",
  1423  
  1424  		"1 Hello\n",
  1425  		"<p>1 Hello</p>\n",
  1426  
  1427  		"1.Hello\n",
  1428  		"<p>1.Hello</p>\n",
  1429  
  1430  		"1.  Hello \n",
  1431  		"<ol>\n<li>Hello</li>\n</ol>\n",
  1432  
  1433  		"1.  Hello \n    Next line \n",
  1434  		"<ol>\n<li>Hello\nNext line</li>\n</ol>\n",
  1435  
  1436  		"Paragraph\n1. No linebreak\n",
  1437  		"<p>Paragraph</p>\n\n<ol>\n<li>No linebreak</li>\n</ol>\n",
  1438  
  1439  		"Paragraph\n\n1. Linebreak\n",
  1440  		"<p>Paragraph</p>\n\n<ol>\n<li>Linebreak</li>\n</ol>\n",
  1441  
  1442  		"1.  List\n    1. Nested list\n",
  1443  		"<ol>\n<li>List\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",
  1444  
  1445  		"1.  List\n\n    1. Nested list\n",
  1446  		"<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested list</li>\n</ol></li>\n</ol>\n",
  1447  
  1448  		"1.  List\n    Second line\n\n    1. Nested\n",
  1449  		"<ol>\n<li><p>List\nSecond line</p>\n\n<ol>\n<li>Nested</li>\n</ol></li>\n</ol>\n",
  1450  
  1451  		"1.  List\n    1. Nested\n\n    Continued\n",
  1452  		"<ol>\n<li><p>List</p>\n\n<ol>\n<li>Nested</li>\n</ol>\n\n<p>Continued</p></li>\n</ol>\n",
  1453  
  1454  		"1.  List\n   1. shallow indent\n",
  1455  		"<ol>\n<li>List\n\n<ol>\n<li>shallow indent</li>\n</ol></li>\n</ol>\n",
  1456  
  1457  		"1. List\n" +
  1458  			" 1. shallow indent\n" +
  1459  			"  2. part of second list\n" +
  1460  			"   3. still second\n" +
  1461  			"    4. almost there\n" +
  1462  			"     1. third level\n",
  1463  		"<ol>\n" +
  1464  			"<li>List\n\n" +
  1465  			"<ol>\n" +
  1466  			"<li>shallow indent</li>\n" +
  1467  			"<li>part of second list</li>\n" +
  1468  			"<li>still second</li>\n" +
  1469  			"<li>almost there\n\n" +
  1470  			"<ol>\n" +
  1471  			"<li>third level</li>\n" +
  1472  			"</ol></li>\n" +
  1473  			"</ol></li>\n" +
  1474  			"</ol>\n",
  1475  
  1476  		"1. List\n        extra indent, same paragraph\n",
  1477  		"<ol>\n<li>List\n    extra indent, same paragraph</li>\n</ol>\n",
  1478  
  1479  		"1. List\n\n        code block\n",
  1480  		"<ol>\n<li><p>List</p>\n\n<pre><code>code block\n</code></pre></li>\n</ol>\n",
  1481  
  1482  		"1. List\n\n          code block with spaces\n",
  1483  		"<ol>\n<li><p>List</p>\n\n<pre><code>  code block with spaces\n</code></pre></li>\n</ol>\n",
  1484  
  1485  		"1. List\n    * Mixted list\n",
  1486  		"<ol>\n<li>List\n\n<ul>\n<li>Mixted list</li>\n</ul></li>\n</ol>\n",
  1487  
  1488  		"1. List\n * Mixed list\n",
  1489  		"<ol>\n<li>List\n\n<ul>\n<li>Mixed list</li>\n</ul></li>\n</ol>\n",
  1490  
  1491  		"* Start with unordered\n 1. Ordered\n",
  1492  		"<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",
  1493  
  1494  		"* Start with unordered\n    1. Ordered\n",
  1495  		"<ul>\n<li>Start with unordered\n\n<ol>\n<li>Ordered</li>\n</ol></li>\n</ul>\n",
  1496  
  1497  		"1. numbers\n1. are ignored\n",
  1498  		"<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n",
  1499  	}
  1500  	doTestsBlock(t, tests, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
  1501  }
  1502  
  1503  func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {
  1504  	var tests = []string{
  1505  		"``` go\nfunc foo() bool {\n\treturn true;\n}\n```\n",
  1506  		"<pre><code class=\"language-go\">func foo() bool {\n\treturn true;\n}\n</code></pre>\n",
  1507  
  1508  		"``` c\n/* special & char < > \" escaping */\n```\n",
  1509  		"<pre><code class=\"language-c\">/* special &amp; char &lt; &gt; &quot; escaping */\n</code></pre>\n",
  1510  
  1511  		"``` c\nno *inline* processing ~~of text~~\n```\n",
  1512  		"<pre><code class=\"language-c\">no *inline* processing ~~of text~~\n</code></pre>\n",
  1513  
  1514  		"```\nNo language\n```\n",
  1515  		"<pre><code>No language\n</code></pre>\n",
  1516  
  1517  		"``` {ocaml}\nlanguage in braces\n```\n",
  1518  		"<pre><code class=\"language-ocaml\">language in braces\n</code></pre>\n",
  1519  
  1520  		"```    {ocaml}      \nwith extra whitespace\n```\n",
  1521  		"<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",
  1522  
  1523  		"```{   ocaml   }\nwith extra whitespace\n```\n",
  1524  		"<pre><code class=\"language-ocaml\">with extra whitespace\n</code></pre>\n",
  1525  
  1526  		"~ ~~ java\nWith whitespace\n~~~\n",
  1527  		"<p>~ ~~ java\nWith whitespace\n~~~</p>\n",
  1528  
  1529  		"~~\nonly two\n~~\n",
  1530  		"<p>~~\nonly two\n~~</p>\n",
  1531  
  1532  		"```` python\nextra\n````\n",
  1533  		"<pre><code class=\"language-python\">extra\n</code></pre>\n",
  1534  
  1535  		"~~~ perl\nthree to start, four to end\n~~~~\n",
  1536  		"<p>~~~ perl\nthree to start, four to end\n~~~~</p>\n",
  1537  
  1538  		"~~~~ perl\nfour to start, three to end\n~~~\n",
  1539  		"<p>~~~~ perl\nfour to start, three to end\n~~~</p>\n",
  1540  
  1541  		"~~~ bash\ntildes\n~~~\n",
  1542  		"<pre><code class=\"language-bash\">tildes\n</code></pre>\n",
  1543  
  1544  		"``` lisp\nno ending\n",
  1545  		"<p>``` lisp\nno ending</p>\n",
  1546  
  1547  		"~~~ lisp\nend with language\n~~~ lisp\n",
  1548  		"<p>~~~ lisp\nend with language\n~~~ lisp</p>\n",
  1549  
  1550  		"```\nmismatched begin and end\n~~~\n",
  1551  		"<p>```\nmismatched begin and end\n~~~</p>\n",
  1552  
  1553  		"~~~\nmismatched begin and end\n```\n",
  1554  		"<p>~~~\nmismatched begin and end\n```</p>\n",
  1555  
  1556  		"   ``` oz\nleading spaces\n```\n",
  1557  		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
  1558  
  1559  		"  ``` oz\nleading spaces\n ```\n",
  1560  		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
  1561  
  1562  		" ``` oz\nleading spaces\n  ```\n",
  1563  		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
  1564  
  1565  		"``` oz\nleading spaces\n   ```\n",
  1566  		"<pre><code class=\"language-oz\">leading spaces\n</code></pre>\n",
  1567  
  1568  		"    ``` oz\nleading spaces\n    ```\n",
  1569  		"<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces</p>\n\n<pre><code>```\n</code></pre>\n",
  1570  	}
  1571  	doTestsBlock(t, tests, EXTENSION_FENCED_CODE|EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK)
  1572  }
  1573  
  1574  func TestTitleBlock_EXTENSION_TITLEBLOCK(t *testing.T) {
  1575  	var tests = []string{
  1576  		"% Some title\n" +
  1577  			"% Another title line\n" +
  1578  			"% Yep, more here too\n",
  1579  		"<h1 class=\"title\">" +
  1580  			"Some title\n" +
  1581  			"Another title line\n" +
  1582  			"Yep, more here too\n" +
  1583  			"</h1>",
  1584  	}
  1585  	doTestsBlock(t, tests, EXTENSION_TITLEBLOCK)
  1586  }
  1587  
  1588  func TestBlockComments(t *testing.T) {
  1589  	var tests = []string{
  1590  		"Some text\n\n<!-- comment -->\n",
  1591  		"<p>Some text</p>\n\n<!-- comment -->\n",
  1592  
  1593  		"Some text\n\n<!--\n\nmultiline\ncomment\n-->\n",
  1594  		"<p>Some text</p>\n\n<!--\n\nmultiline\ncomment\n-->\n",
  1595  
  1596  		"Some text\n\n<!--\n\n<div><p>Commented</p>\n<span>html</span></div>\n-->\n",
  1597  		"<p>Some text</p>\n\n<!--\n\n<div><p>Commented</p>\n<span>html</span></div>\n-->\n",
  1598  	}
  1599  	doTestsBlock(t, tests, 0)
  1600  }
  1601  
  1602  func TestCDATA(t *testing.T) {
  1603  	var tests = []string{
  1604  		"Some text\n\n<![CDATA[foo]]>\n",
  1605  		"<p>Some text</p>\n\n<![CDATA[foo]]>\n",
  1606  
  1607  		"CDATA ]]\n\n<![CDATA[]]]]>\n",
  1608  		"<p>CDATA ]]</p>\n\n<![CDATA[]]]]>\n",
  1609  
  1610  		"CDATA >\n\n<![CDATA[>]]>\n",
  1611  		"<p>CDATA &gt;</p>\n\n<![CDATA[>]]>\n",
  1612  
  1613  		"Lots of text\n\n<![CDATA[lots of te><t\non\nseveral\nlines]]>\n",
  1614  		"<p>Lots of text</p>\n\n<![CDATA[lots of te><t\non\nseveral\nlines]]>\n",
  1615  
  1616  		"<![CDATA[>]]>\n",
  1617  		"<![CDATA[>]]>\n",
  1618  	}
  1619  	doTestsBlock(t, tests, 0)
  1620  	doTestsBlock(t, []string{
  1621  		"``` html\n<![CDATA[foo]]>\n```\n",
  1622  		"<pre><code class=\"language-html\">&lt;![CDATA[foo]]&gt;\n</code></pre>\n",
  1623  
  1624  		"<![CDATA[\n``` python\ndef func():\n    pass\n```\n]]>\n",
  1625  		"<![CDATA[\n``` python\ndef func():\n    pass\n```\n]]>\n",
  1626  
  1627  		`<![CDATA[
  1628  > def func():
  1629  >     pass
  1630  ]]>
  1631  `,
  1632  		`<![CDATA[
  1633  > def func():
  1634  >     pass
  1635  ]]>
  1636  `,
  1637  	}, EXTENSION_FENCED_CODE)
  1638  }