public function testConsecutiveBlankLines() { $parser = new Parser(); $this->assertEquals($parser->parse("- Foo\n\n bar\n\n baz"), "<ul>\n<li>\n<p>Foo</p>\n<pre><code>bar\n\nbaz\n</code></pre>\n</li>\n</ul>", "One blank line is fine..."); $this->assertEquals($parser->parse("- Foo\n\n bar\n\n\n baz"), "<ul>\n<li>\n<p>Foo</p>\n<pre><code>bar\n</code></pre>\n</li>\n</ul>\n<pre><code> baz\n</code></pre>", "Two blank lines interrupt lists"); $this->assertEquals($parser->parse("- foo\n\n bar\n\n- foo\n\n\n bar\n\n- ```\n foo\n\n\n bar\n ```\n\n- baz\n\n + ```\n foo\n\n\n bar\n ```"), "<ul>\n<li>\n<p>foo</p>\n<p>bar</p>\n</li>\n<li>\n<p>foo</p>\n</li>\n</ul>\n<p>bar</p>\n<ul>\n<li>\n<pre><code>foo\n\n\nbar\n</code></pre>\n</li>\n<li>\n<p>baz</p>\n<ul>\n<li>\n<pre><code>foo\n\n\nbar\n</code></pre>\n</li>\n</ul>\n</li>\n</ul>", "Two consecutive blank lines interrupt lists... except if they're contained in a *fenced* code block"); }
public function testCannotBeLazyContinuationLine() { $parser = new Parser(); $this->assertEquals($parser->parse("> Foo\n---"), "<blockquote><p>Foo</p></blockquote>\n<hr />", "Setext headings' underlining cannot be a lazy continuation line in a blockquote"); $this->assertEquals($parser->parse("> Foo\nbar\n==="), "<blockquote><p>Foo\nbar\n===</p></blockquote>", "Setext headings' underlining cannot be a lazy continuation line in a blockquote"); $this->assertEquals($parser->parse("- Foo\n---"), "<ul><li>Foo</li></ul>\n<hr />", "Setext headings' underlining cannot be a lazy continuation line in a list"); }
public function testPrecedence() { $parser = new Parser(); $this->assertEquals($parser->parse(" > # Foo\n > bar\n > baz"), "<pre><code>> # Foo\n> bar\n> baz\n</code></pre>", "Indented code blocks have precedence over block quotes"); $this->assertEquals($parser->parse("foo\n> bar"), "<p>foo</p>\n<blockquote>\n<p>bar</p>\n</blockquote>", "Block quotes can interrupt paragraphs"); $this->assertEquals($parser->parse("> aaa\n***\n> bbb"), "<blockquote>\n<p>aaa</p>\n</blockquote>\n<hr />\n<blockquote>\n<p>bbb</p>\n</blockquote>", "Blank lines are not needed before or after block quotes"); }
public function testPrecedence() { $parser = new Parser(); $this->assertEquals($parser->parse("foo\n***\nbar"), "<p>foo</p>\n<hr />\n<p>bar</p>", "Thembreaks have precedence over paragraphs"); $this->assertEquals($parser->parse("Foo\n---\nbar"), "<h2>Foo</h2>\n<p>bar</p>", "Headlines have precedence over thembreaks"); $this->assertEquals($parser->parse("- foo\n---\n- bar"), "<ul><li>foo</li></ul>\n<hr />\n<ul><li>bar</li></ul>", "Thembreaks have precedence over lists"); }
public function testPrecedence() { $parser = new Parser(); $this->assertEquals($parser->parse(" [foo]: /url \"title\"\n\n[foo]"), "<pre><code>[foo]: /url "title"\n</code></pre>\n<p>[foo]</p>", "Indented code blocks have precedence over link definitions"); $this->assertEquals($parser->parse("```\n[foo2]: /url\n```\n\n[foo2]"), "<pre><code>[foo2]: /url\n</code></pre>\n<p>[foo2]</p>", "Fenced code blocks have precedence over link definitions"); $this->assertEquals($parser->parse("Foo\n[bar]: /baz\n\n[bar]"), "<p>Foo\n[bar]: /baz</p>\n<p>[bar]</p>", "Link definitions cannot interrupt a paragraph"); $this->assertEquals($parser->parse("[foo4]: /foo-url \"foo\"\n[bar2]: /bar-url\n \"bar\"\n[baz]: /baz-url\n\n[foo4],\n[bar2],\n[baz]"), "<p><a href=\"/foo-url\" title=\"foo\">foo4</a>,\n<a href=\"/bar-url\" title=\"bar\">bar2</a>,\n<a href=\"/baz-url\">baz</a></p>", "Multiple link definitions can occur without blank lines in between"); $this->assertEquals($parser->parse("# [Foo3]\n[foo3]: /url\n> bar"), "<h1><a href=\"/url\">Foo3</a></h1>\n<blockquote>\n<p>bar</p>\n</blockquote>", "Link definitions have precedence over other blocks and don't need blank lines after"); }
public function testInfoString() { $parser = new Parser(); $this->assertEquals($parser->parse("```python\ndef foo(x):\n return 4\n```"), "<pre><code class=\"language-python\">def foo(x):\n return 4\n</code></pre>", "The first word of the info string is used as class attribute for code element"); $this->assertEquals($parser->parse("~~~ python startline=4 etc \ndef foo(x):\n return 4\n~~~"), "<pre><code class=\"language-python\">def foo(x):\n return 4\n</code></pre>", "Only the first word of the info string is used, stripped from spaces"); $this->assertEquals($parser->parse("````;\n````"), "<pre><code class=\"language-;\"></code></pre>", "Info strings are not smart"); $this->assertEquals($parser->parse("``` aa ```\nfoo"), "<p><code>aa</code>\nfoo</p>", "Info strings cannot contain backticks if the fence is composed of backticks"); $this->assertEquals($parser->parse("```\n``` aaa\n```"), "<pre><code>``` aaa\n</code></pre>", "Closing fences cannot have info strings"); }
public function testSpaces() { $parser = new Parser(); $this->assertEquals($parser->parse(" <!-- foo -->\n\n <!-- foo -->"), " <!-- foo -->\n<pre><code><!-- foo -->\n</code></pre>", "Opening tags can be indented up to 3 spaces, no more"); }
public function testPrecedence() { $parser = new Parser(); $this->assertEquals($parser->parse("aaa\n bbb\n ccc"), "<p>aaa\nbbb\nccc</p>", "Code blocks cannot interrupt paragraphs"); $this->assertEquals($parser->parse(" aaa\nbbb"), "<pre><code>aaa\n</code></pre>\n<p>bbb</p>", "Code blocks still exist though."); }
/** * more complex scenarios are tested by writing the markdown and expected * html output in a file, in the ./data folder. * * @dataProvider getDataFiles */ public function testFromDataFiles($markdown, $html, $description) { $parser = new Parser(); $this->assertEquals($parser->parse($markdown), $html, $description); }
public function testPrecedence() { $parser = new Parser(); $this->assertEquals($parser->parse("Foo\n# bar\nbaz"), "<p>Foo</p>\n<h1>bar</h1>\n<p>baz</p>", "ATX headings can break paragraphs"); $this->assertEquals($parser->parse("***\n## lol\n*****"), "<hr />\n<h2>lol</h2>\n<hr />", "ATX headings do not need blank lines before nor after them"); }