Last active
August 12, 2016 09:59
-
-
Save apfelbox/f6bfcf7fe14ebb5d5171 to your computer and use it in GitHub Desktop.
Adjusted parser to render paragraphs which only contain a single image without the paragraph. So instead <p><img ...></p> it just renders<img ...>
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 | |
/** | |
* Adjusted parser to render paragraphs which only contain a single image without the paragraph. | |
* | |
* So instead | |
* <p><img ...></p> | |
* | |
* it just renders | |
* <img ...> | |
*/ | |
class Parser extends Parsedown | |
{ | |
/** | |
* The regex which matches an markdown image definition | |
* | |
* @var string | |
*/ | |
private $markdownImage = "~^!\[.*?\]\(.*?\)$~"; | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function paragraph($Line) | |
{ | |
if (1 === preg_match($this->markdownImage, $Line["text"])) | |
{ | |
return $this->inlineImage($Line['text']); | |
} | |
return parent::paragraph($Line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for most recent version, see https://gist.github.com/fxck/d65255218de3611df3cd and erusev/parsedown#180