Skip to content

Commit

Permalink
Rename hashtags enabled to strict mode
Browse files Browse the repository at this point in the history
We can use this to seperate any intentional spec deviations from
spec behaviour so users can pick between compatability and spec
implementations
  • Loading branch information
aidantwoods committed Apr 2, 2018
1 parent d0279cd commit cf6d23d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ function setSafeMode($safeMode)

protected $safeMode;

function setHastagsEnabled($hashtagsEnabled)
function setStrictMode($strictMode)
{
$this->hashtagsEnabled = (bool) $hashtagsEnabled;
$this->strictMode = (bool) $strictMode;

return $this;
}

protected $hashtagsEnabled;
protected $strictMode;

protected $safeLinksWhitelist = array(
'http://',
Expand Down Expand Up @@ -529,7 +529,8 @@ protected function blockHeader($Line)

$text = trim($Line['text'], '#');

if ($this->hashtagsEnabled and (!isset($text[0]) or $text[0] !== ' ')) {
if ($this->strictMode and ( ! isset($text[0]) or $text[0] !== ' '))
{
return;
}

Expand Down
2 changes: 1 addition & 1 deletion test/ParsedownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ protected function initDirs()
protected function initParsedown()
{
$Parsedown = new TestParsedown();
$Parsedown->setHastagsEnabled(true);

return $Parsedown;
}
Expand All @@ -52,6 +51,7 @@ function test_($test, $dir)
$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);

Expand Down
3 changes: 1 addition & 2 deletions test/data/atx_heading.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ <h6>h6</h6>
<p>####### not a heading</p>
<h1>closed h1</h1>
<p>#</p>
<p>##</p>
<h1># of levels</h1>
<h1># of levels #</h1>
<p>#hashtag</p>
<h1>heading</h1>
4 changes: 1 addition & 3 deletions test/data/atx_heading.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

#

##

# # of levels

# # of levels # #

#hashtag
#heading
13 changes: 13 additions & 0 deletions test/data/strict_atx_heading.html
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions test/data/strict_atx_heading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# h1

## h2

### h3

#### h4

##### h5

###### h6

####### not a heading

#not a heading

# closed h1 #

#

##

# # of levels

# # of levels # #

0 comments on commit cf6d23d

Please sign in to comment.