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 = "Lorem ipsum
"; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_header_underlineH2() { $markdown = "Header 2\n---\n\nLorem ipsum"; $expected = "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 = 'Testing
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 = '
'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_blockquote_list() { $markdown = "> 1. Lorem\n> 2. Ipsum"; $expected = 'Lorem ipsum dolor
Sit amet
'; $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 = "
- Lorem
- Ipsum
Code
\n\nfunction foo() {\n return 'bar';\n}\n\nend
"; $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\nfunction foo() {\n return 'bar';\n}\n\nend
"; $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\nfunction foo() {\n return 'bar';\n}\n\nend
"; $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 A | Column B | Column C |
|---|---|---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| Column A | Column B | Column C |
|---|---|---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| Column A | ' . 'Column B | ' . 'Column C | ' . '
|---|---|---|
| 1 | ' . '2 | ' . '3 | ' . '
| 4 | ' . '5 | ' . '6 | ' . '
| Column A | ' . '' . ' | Column C | ' . '
|---|---|---|
| 1 | ' . '2 | ' . '' . ' |
| 4 | ' . '' . ' | 6 | ' . '
| ' . ' | 8 | ' . '9 | ' . '
Lorem ipsum1 ' . 'dolor2 ' . 'sit1 amet
' . ''; $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); } }