Merge pull request #589 from NathanBaulch/hashtag
Support #hashtag per CommonMark and GFM specs
This commit is contained in:
commit
498c88c4eb
|
@ -90,6 +90,15 @@ class Parsedown
|
||||||
|
|
||||||
protected $safeMode;
|
protected $safeMode;
|
||||||
|
|
||||||
|
function setStrictMode($strictMode)
|
||||||
|
{
|
||||||
|
$this->strictMode = (bool) $strictMode;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $strictMode;
|
||||||
|
|
||||||
protected $safeLinksWhitelist = array(
|
protected $safeLinksWhitelist = array(
|
||||||
'http://',
|
'http://',
|
||||||
'https://',
|
'https://',
|
||||||
|
@ -504,36 +513,39 @@ class Parsedown
|
||||||
|
|
||||||
protected function blockHeader($Line)
|
protected function blockHeader($Line)
|
||||||
{
|
{
|
||||||
if (isset($Line['text'][1]))
|
$level = 1;
|
||||||
|
|
||||||
|
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
|
||||||
{
|
{
|
||||||
$level = 1;
|
$level ++;
|
||||||
|
|
||||||
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
|
|
||||||
{
|
|
||||||
$level ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($level > 6)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$text = trim($Line['text'], '#');
|
|
||||||
$text = trim($text, ' ');
|
|
||||||
|
|
||||||
$Block = array(
|
|
||||||
'element' => array(
|
|
||||||
'name' => 'h' . min(6, $level),
|
|
||||||
'handler' => array(
|
|
||||||
'function' => 'lineElements',
|
|
||||||
'argument' => $text,
|
|
||||||
'destination' => 'elements',
|
|
||||||
)
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $Block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($level > 6)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = trim($Line['text'], '#');
|
||||||
|
|
||||||
|
if ($this->strictMode and isset($text[0]) and $text[0] !== ' ')
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$text = trim($text, ' ');
|
||||||
|
|
||||||
|
$Block = array(
|
||||||
|
'element' => array(
|
||||||
|
'name' => 'h' . min(6, $level),
|
||||||
|
'handler' => array(
|
||||||
|
'function' => 'lineElements',
|
||||||
|
'argument' => $text,
|
||||||
|
'destination' => 'elements',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $Block;
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -51,6 +51,7 @@ class ParsedownTest extends TestCase
|
||||||
$expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
|
$expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
|
||||||
|
|
||||||
$this->Parsedown->setSafeMode(substr($test, 0, 3) === 'xss');
|
$this->Parsedown->setSafeMode(substr($test, 0, 3) === 'xss');
|
||||||
|
$this->Parsedown->setStrictMode(substr($test, 0, 6) === 'strict');
|
||||||
|
|
||||||
$actualMarkup = $this->Parsedown->text($markdown);
|
$actualMarkup = $this->Parsedown->text($markdown);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
<h6>h6</h6>
|
<h6>h6</h6>
|
||||||
<p>####### not a heading</p>
|
<p>####### not a heading</p>
|
||||||
<h1>closed h1</h1>
|
<h1>closed h1</h1>
|
||||||
<p>#</p>
|
<h1></h1>
|
||||||
|
<h2></h2>
|
||||||
<h1># of levels</h1>
|
<h1># of levels</h1>
|
||||||
<h1># of levels #</h1>
|
<h1># of levels #</h1>
|
||||||
|
<h1>heading</h1>
|
|
@ -16,6 +16,10 @@
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
# # of levels
|
# # of levels
|
||||||
|
|
||||||
# # of levels # #
|
# # of levels # #
|
||||||
|
|
||||||
|
#heading
|
|
@ -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>
|
|
@ -0,0 +1,25 @@
|
||||||
|
# h1
|
||||||
|
|
||||||
|
## h2
|
||||||
|
|
||||||
|
### h3
|
||||||
|
|
||||||
|
#### h4
|
||||||
|
|
||||||
|
##### h5
|
||||||
|
|
||||||
|
###### h6
|
||||||
|
|
||||||
|
####### not a heading
|
||||||
|
|
||||||
|
#not a heading
|
||||||
|
|
||||||
|
# closed h1 #
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
|
# # of levels
|
||||||
|
|
||||||
|
# # of levels # #
|
Loading…
Reference in New Issue