Created
January 13, 2015 20:53
-
-
Save fxck/d65255218de3611df3cd 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 hidden or 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