class BlockTests extends BaseTest { /** @type {Markdown} */ parser; md(markdown) { return normalizeWhitespace(this.parser.toHTML(markdown)); } setUp() { this.parser = Markdown.completeParser; } test_paragraphs() { let markdown = "Lorem ipsum\n\nDolor sit amet"; let expected = "

Lorem ipsum

Dolor sit amet

"; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_paragraph_lineGrouping() { let markdown = "Lorem ipsum\ndolor sit amet"; let expected = "Lorem ipsum dolor sit amet"; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_header_underlineH1() { let markdown = "Header 1\n===\n\nLorem ipsum"; let expected = "

Header 1

Lorem ipsum

"; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_header_underlineH2() { let markdown = "Header 2\n---\n\nLorem ipsum"; let expected = "

Header 2

Lorem ipsum

"; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_header_hash() { let markdown = "# Header 1\n## Header 2\n### Header 3\n#### Header 4\n##### Header 5\n###### Header 6\n"; let expected = '

Header 1

Header 2

Header 3

Header 4

Header 5
Header 6
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_header_hash_trailing() { let markdown = "# Header 1 #\n## Header 2 ##\n### Header 3 ######"; let expected = '

Header 1

Header 2

Header 3

'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_unorderedList() { let markdown = "* Lorem\n* Ipsum\n* Dolor"; let expected = ''; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_unorderedList_nested() { let markdown = "* Lorem\n + Ipsum\n* Dolor"; let expected = ''; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_unorderedList_hitch() { // This incomplete bulleted list locked up the browser at one // point, not forever but a REALLY long time this.profile(1.0, () => { let markdown = "Testing\n\n* "; let expected = '

Testing

'; let actual = this.md(markdown); this.assertEqual(expected, actual); }); } test_orderedList() { let markdown = "1. Lorem\n1. Ipsum\n5. Dolor"; let expected = '
  1. Lorem
  2. Ipsum
  3. Dolor
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_orderedList_numbering() { let markdown = "4. Lorem\n1. Ipsum\n9. Dolor"; let expected = '
  1. Lorem
  2. Ipsum
  3. Dolor
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_orderedList_nested1() { let markdown = "1. Lorem\n 1. Ipsum\n1. Dolor"; let expected = '
  1. Lorem
    1. Ipsum
  2. Dolor
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_orderedList_nested2() { let markdown = "1. Lorem\n 1. Ipsum\n 1. Dolor\n 1. Sit\n1. Amet"; let expected = '
  1. Lorem
    1. Ipsum
      1. Dolor
    2. Sit
  2. Amet
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_blockquote() { let markdown = '> Lorem ipsum dolor'; let expected = '
Lorem ipsum dolor
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_blockquote_paragraphs() { let markdown = '> Lorem ipsum dolor\n>\n>Sit amet'; let expected = '

Lorem ipsum dolor

Sit amet

'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_blockquote_list() { let markdown = '> 1. Lorem\n> 2. Ipsum'; let expected = '
  1. Lorem
  2. Ipsum
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_codeBlock_indented() { let markdown = "Code\n\n function foo() {\n return 'bar';\n }\n\nend"; let expected = "

Code

\n\n
function foo() {\n    return 'bar';\n}
\n\n

end

"; let actual = this.parser.toHTML(markdown).trim(); // don't normalize whitespace this.assertEqual(expected.replace(/ /g, '⎵'), actual.replace(/ /g, '⎵')); } test_codeBlock_fenced() { let markdown = "Code\n\n```\nfunction foo() {\n return 'bar';\n}\n```\n\nend"; let expected = "

Code

\n\n
function foo() {\n    return 'bar';\n}
\n\n

end

"; let actual = this.parser.toHTML(markdown).trim(); // don't normalize whitespace this.assertEqual(expected.replace(/ /g, '⎵'), actual.replace(/ /g, '⎵')); } test_codeBlock_fenced_language() { let markdown = "Code\n\n```javascript\nfunction foo() {\n return 'bar';\n}\n```\n\nend"; let expected = "

Code

\n\n
function foo() {\n    return 'bar';\n}
\n\n

end

"; let actual = this.parser.toHTML(markdown).trim(); // don't normalize whitespace this.assertEqual(expected.replace(/ /g, '⎵'), actual.replace(/ /g, '⎵')); } test_horizontalRule() { let markdown = "Before\n\n---\n\n- - -\n\n***\n\n* * * * * * *\n\nafter"; let expected = "

Before





after

"; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_table_unfenced() { let markdown = "Column A | Column B | Column C\n--- | --- | ---\n1 | 2 | 3\n4 | 5 | 6"; let expected = "
Column AColumn BColumn C
123
456
"; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_table_fenced() { let markdown = "| Column A | Column B | Column C |\n| --- | --- | --- |\n| 1 | 2 | 3\n4 | 5 | 6 |"; let expected = "
Column AColumn BColumn C
123
456
"; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_table_alignment() { let markdown = 'Column A | Column B | Column C\n' + ':--- | :---: | ---:\n' + '1 | 2 | 3\n' + '4 | 5 | 6'; let expected = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
Column AColumn BColumn C
123
456
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_table_holes() { let markdown = 'Column A||Column C\n' + '---|---|---\n' + '|1|2||\n' + '|4||6|\n' + '||8|9|'; let expected = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
Column AColumn C
12
46
89
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_definitionList() { let markdown = 'term\n' + ': definition\n' + 'another' + ' term\n' + ': def 1\n' + ' broken on next line\n' + ': def 2'; let expected = '
' + '
term
' + '
definition
' + '
another term
' + '
def 1 broken on next line
' + '
def 2
' + '
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_footnotes() { let markdown = 'Lorem ipsum[^1] dolor[^abc] sit[^1] amet\n\n[^1]: A footnote\n[^abc]: Another footnote'; let expected = '

Lorem ipsum1 ' + 'dolor2 ' + 'sit1 amet

' + '
' + '
    ' + '
  1. A footnote ↩︎↩︎
  2. ' + '
  3. Another footnote ↩︎
  4. ' + '
' + '
'; let actual = this.md(markdown); this.assertEqual(expected, actual); } test_abbreviations() { let markdown = 'Lorem ipsum HTML dolor HTML sit\n' + '\n' + '*[HTML]: Hypertext Markup Language'; let expected = '

Lorem ipsum HTML dolor HTML sit

'; let actual = this.md(markdown); this.assertEqual(expected, actual); } }