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 @@ -

h1

-

h2

-

h3

-

h4

-
h5
-
h6
-

####### not a heading

-

closed h1

-

-

-

# of levels

-

# of levels #

-

heading

\ No newline at end of file +

h1

+

h2

+

h3

+

h4

+
h5
+
h6
+

####### not a heading

+

closed h1

+

+

+

# of levels

+

# of levels #

+

heading

diff --git a/test/data/strict_atx_heading.html b/test/data/strict_atx_heading.html index 11cf4df..c934064 100644 --- a/test/data/strict_atx_heading.html +++ b/test/data/strict_atx_heading.html @@ -1,13 +1,13 @@ -

h1

-

h2

-

h3

-

h4

-
h5
-
h6
+

h1

+

h2

+

h3

+

h4

+
h5
+
h6

####### not a heading

#not a heading

-

closed h1

+

closed h1

-

# of levels

-

# of levels #

\ No newline at end of file +

# of levels

+

# of levels #