diff --git a/Parsedown.php b/Parsedown.php index 6e2a8e1..006d9db 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -554,13 +554,17 @@ class Parsedown $text = trim($text, ' '); $link = strtolower(str_replace(' ','-',$text)); + $attr = array(); + if (!empty($link)) { + $attr = array( + 'id' => $link, + ); + } $Block = array( 'element' => array( 'name' => 'h' . $level, - 'attributes' => array( - 'id' => $link, - ), + 'attributes' => $attr, 'handler' => array( 'function' => 'lineElements', 'argument' => $text, diff --git a/test/ParsedownTest.php b/test/ParsedownTest.php index bf40317..8112537 100755 --- a/test/ParsedownTest.php +++ b/test/ParsedownTest.php @@ -54,8 +54,10 @@ class ParsedownTest extends TestCase $this->Parsedown->setStrictMode(substr($test, 0, 6) === 'strict'); $actualMarkup = $this->Parsedown->text($markdown); + $actualMarkup = str_replace("\r\n", "\n", $actualMarkup); + $actualMarkup = str_replace("\r", "\n", $actualMarkup); - $this->assertEquals($expectedMarkup, $actualMarkup); + $this->assertEquals(trim($expectedMarkup), trim($actualMarkup)); } function testRawHtml() diff --git a/test/data/atx_heading.html b/test/data/atx_heading.html index 3b09c38..80bceea 100644 --- a/test/data/atx_heading.html +++ b/test/data/atx_heading.html @@ -1,13 +1,13 @@ -
####### not a heading
-####### not a heading
+####### not a heading
#not a heading
-