Created
July 16, 2016 15:25
-
-
Save integer/05dea90948c4e96a254bb2508151d1ef to your computer and use it in GitHub Desktop.
Comments for Parsedown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Adds support for | |
* {comm} | |
* Multiline comment block | |
* {/comm} | |
* and {lcomm}inline comment{/lcomm}. | |
* | |
* Comments will be ignored in page output. | |
* | |
* Inline comments over whole line produce empty <p> tag. This change fix it: https://github.com/integer/parsedown/commit/c28065b8c107ecb0117674598f55ba70346aee41 | |
*/ | |
class ParseDownExtension extends Parsedown | |
{ | |
public function __construct() | |
{ | |
$this->InlineTypes['{'] []= 'CommentInline'; | |
$this->inlineMarkerList .= '{'; | |
$this->BlockTypes['{'] []= 'CommentBlock'; | |
} | |
protected function inlineCommentInline($Excerpt) | |
{ | |
if (preg_match('/^{lcomm}(.*?){\/lcomm}/', $Excerpt['text'], $matches)) | |
{ | |
return array( | |
'extent' => strlen($matches[0]), | |
'markup' => '', | |
'text' => null, | |
); | |
} | |
} | |
protected function blockCommentBlock($Line, $Block) | |
{ | |
if (preg_match('/\{comm\}/', $Line['text'], $matches)) | |
{ | |
return array( | |
'hidden' => true, | |
); | |
} | |
} | |
protected function blockCommentBlockContinue($Line, $Block) | |
{ | |
if (isset($Block['complete'])) { | |
return; | |
} | |
// A blank newline has occurred | |
if (isset($Block['interrupted'])) { | |
unset($Block['interrupted']); | |
} | |
//Check for end of the block. | |
if (preg_match('/\{\/comm\}/', $Line['text'])) { | |
$Block['complete'] = true; | |
return $Block; | |
} | |
return $Block; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment