diff --git a/Parsedown.php b/Parsedown.php index ae0cbdecd..facca5720 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -553,15 +553,23 @@ protected function blockHeader($Line) } $text = trim($text, ' '); + $link = preg_replace('/[^\p{L}\p{N}\p{M}-]+/u', '', mb_strtolower(mb_ereg_replace(' ','-',$text))); + $attr = array(); + if (!empty($link)) { + $attr = array( + 'id' => $link, + ); + } $Block = array( 'element' => array( 'name' => 'h' . $level, + 'attributes' => $attr, 'handler' => array( 'function' => 'lineElements', 'argument' => $text, 'destination' => 'elements', - ) + ), ), ); @@ -1992,3 +2000,4 @@ static function instance($name = 'default') 'wbr', 'time', ); } + diff --git a/test/ParsedownTest.php b/test/ParsedownTest.php index bf4031759..8112537b7 100755 --- a/test/ParsedownTest.php +++ b/test/ParsedownTest.php @@ -54,8 +54,10 @@ function test_($test, $dir) $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 3b09c38dc..80bceeac0 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
-