parser = Markdown::completeParser(); } private function md(string $markdown): string { return $this->normalizeWhitespace($this->parser->toHTML($markdown)); } private function normalizeWhitespace(string $str): string { $str = mb_eregi_replace('\\s+', ' ', $str); $str = mb_eregi_replace('>\\s+<', '><', $str); return trim($str); } public function test_paragraphs() { $markdown = "Lorem ipsum\n\nDolor sit amet"; $expected = "

Lorem ipsum

Dolor sit amet

"; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_paragraph_lineGrouping() { $markdown = "Lorem ipsum\ndolor sit amet"; $expected = "Lorem ipsum dolor sit amet"; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_header_underlineH1() { $markdown = "Header 1\n===\n\nLorem ipsum"; $expected = "

Header 1

Lorem ipsum

"; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_header_underlineH2() { $markdown = "Header 2\n---\n\nLorem ipsum"; $expected = "

Header 2

Lorem ipsum

"; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_header_hash() { $markdown = "# Header 1\n## Header 2\n### Header 3\n#### Header 4\n##### Header 5\n###### Header 6\n"; $expected = '

Header 1

Header 2

Header 3

Header 4

Header 5
Header 6
'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_header_hash_trailing() { $markdown = "# Header 1 #\n## Header 2 ##\n### Header 3 ######"; $expected = '

Header 1

Header 2

Header 3

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

Testing

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

Lorem ipsum dolor

Sit amet

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

Code

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

end

"; $actual = trim($this->parser->toHTML($markdown)); // don't normalize whitespace $this->assertSame(mb_ereg_replace(' ', '⎵', $expected), mb_ereg_replace(' ', '⎵', $actual)); } public function test_codeBlock_fenced() { $markdown = "Code\n\n```\nfunction foo() {\n return 'bar';\n}\n```\n\nend"; $expected = "

Code

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

end

"; $actual = trim($this->parser->toHTML($markdown)); // don't normalize whitespace $this->assertSame(mb_ereg_replace(' ', '⎵', $expected), mb_ereg_replace(' ', '⎵', $actual)); } public function test_codeBlock_fenced_language() { $markdown = "Code\n\n```javascript\nfunction foo() {\n return 'bar';\n}\n```\n\nend"; $expected = "

Code

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

end

"; $actual = trim($this->parser->toHTML($markdown)); // don't normalize whitespace $this->assertSame(mb_ereg_replace(' ', '⎵', $expected), mb_ereg_replace(' ', '⎵', $actual)); } public function test_horizontalRule() { $markdown = "Before\n\n---\n\n- - -\n\n***\n\n* * * * * * *\n\nafter"; $expected = "

Before





after

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

Lorem ipsum1 ' . 'dolor2 ' . 'sit1 amet

' . '
' . '
    ' . '
  1. A footnote ↩︎↩︎
  2. ' . '
  3. Another footnote ↩︎
  4. ' . '
' . '
'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_abbreviations() { $markdown = "Lorem ipsum HTML dolor HTML sit\n" . "\n" . "*[HTML]: Hypertext Markup Language"; $expected = '

Lorem ipsum HTML dolor HTML sit

'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } }