mirror of
https://github.com/erusev/parsedown.git
synced 2025-01-17 20:58:23 +01:00
Merge pull request #589 from NathanBaulch/hashtag
Support #hashtag per CommonMark and GFM specs
This commit is contained in:
commit
498c88c4eb
18
Parsedown.php
Normal file → Executable file
18
Parsedown.php
Normal file → Executable file
@ -90,6 +90,15 @@ class Parsedown
|
||||
|
||||
protected $safeMode;
|
||||
|
||||
function setStrictMode($strictMode)
|
||||
{
|
||||
$this->strictMode = (bool) $strictMode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected $strictMode;
|
||||
|
||||
protected $safeLinksWhitelist = array(
|
||||
'http://',
|
||||
'https://',
|
||||
@ -503,8 +512,6 @@ class Parsedown
|
||||
# Header
|
||||
|
||||
protected function blockHeader($Line)
|
||||
{
|
||||
if (isset($Line['text'][1]))
|
||||
{
|
||||
$level = 1;
|
||||
|
||||
@ -519,6 +526,12 @@ class Parsedown
|
||||
}
|
||||
|
||||
$text = trim($Line['text'], '#');
|
||||
|
||||
if ($this->strictMode and isset($text[0]) and $text[0] !== ' ')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$text = trim($text, ' ');
|
||||
|
||||
$Block = array(
|
||||
@ -534,7 +547,6 @@ class Parsedown
|
||||
|
||||
return $Block;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# List
|
||||
|
1
test/ParsedownTest.php
Normal file → Executable file
1
test/ParsedownTest.php
Normal file → Executable file
@ -51,6 +51,7 @@ class ParsedownTest extends TestCase
|
||||
$expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
|
||||
|
||||
$this->Parsedown->setSafeMode(substr($test, 0, 3) === 'xss');
|
||||
$this->Parsedown->setStrictMode(substr($test, 0, 6) === 'strict');
|
||||
|
||||
$actualMarkup = $this->Parsedown->text($markdown);
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
<h6>h6</h6>
|
||||
<p>####### not a heading</p>
|
||||
<h1>closed h1</h1>
|
||||
<p>#</p>
|
||||
<h1></h1>
|
||||
<h2></h2>
|
||||
<h1># of levels</h1>
|
||||
<h1># of levels #</h1>
|
||||
<h1>heading</h1>
|
@ -16,6 +16,10 @@
|
||||
|
||||
#
|
||||
|
||||
##
|
||||
|
||||
# # of levels
|
||||
|
||||
# # of levels # #
|
||||
|
||||
#heading
|
13
test/data/strict_atx_heading.html
Normal file
13
test/data/strict_atx_heading.html
Normal file
@ -0,0 +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>
|
||||
<p>#not a heading</p>
|
||||
<h1>closed h1</h1>
|
||||
<h1></h1>
|
||||
<h2></h2>
|
||||
<h1># of levels</h1>
|
||||
<h1># of levels #</h1>
|
25
test/data/strict_atx_heading.md
Normal file
25
test/data/strict_atx_heading.md
Normal file
@ -0,0 +1,25 @@
|
||||
# h1
|
||||
|
||||
## h2
|
||||
|
||||
### h3
|
||||
|
||||
#### h4
|
||||
|
||||
##### h5
|
||||
|
||||
###### h6
|
||||
|
||||
####### not a heading
|
||||
|
||||
#not a heading
|
||||
|
||||
# closed h1 #
|
||||
|
||||
#
|
||||
|
||||
##
|
||||
|
||||
# # of levels
|
||||
|
||||
# # of levels # #
|
Loading…
x
Reference in New Issue
Block a user