This commit is contained in:
Mark Brugnoli-Vinten 2020-08-25 13:48:46 +02:00 committed by GitHub
commit 899f74dc4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 24 deletions

View File

@ -553,15 +553,23 @@ class Parsedown
}
$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 @@ class Parsedown
'wbr', 'time',
);
}

View File

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

View File

@ -1,13 +1,13 @@
<h1>h1</h1>
<h2>h2</h2>
<h3>h3</h3>
<h4>h4</h4>
<h5>h5</h5>
<h6>h6</h6>
<p>####### not a heading</p>
<h1>closed h1</h1>
<h1></h1>
<h2></h2>
<h1># of levels</h1>
<h1># of levels #</h1>
<h1>heading</h1>
<h1 id="h1">h1</h1>
<h2 id="h2">h2</h2>
<h3 id="h3">h3</h3>
<h4 id="h4">h4</h4>
<h5 id="h5">h5</h5>
<h6 id="h6">h6</h6>
<p>####### not a heading</p>
<h1 id="closed-h1">closed h1</h1>
<h1></h1>
<h2></h2>
<h1 id="#-of-levels"># of levels</h1>
<h1 id="#-of-levels-#"># of levels #</h1>
<h1 id="heading">heading</h1>

View File

@ -1,13 +1,13 @@
<h1>h1</h1>
<h2>h2</h2>
<h3>h3</h3>
<h4>h4</h4>
<h5>h5</h5>
<h6>h6</h6>
<h1 id="h1">h1</h1>
<h2 id="h2">h2</h2>
<h3 id="h3">h3</h3>
<h4 id="h4">h4</h4>
<h5 id="h5">h5</h5>
<h6 id="h6">h6</h6>
<p>####### not a heading</p>
<p>#not a heading</p>
<h1>closed h1</h1>
<h1 id="closed-h1">closed h1</h1>
<h1></h1>
<h2></h2>
<h1># of levels</h1>
<h1># of levels #</h1>
<h1 id="#-of-levels"># of levels</h1>
<h1 id="#-of-levels-#"># of levels #</h1>