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