Skip to content

Instantly share code, notes, and snippets.

@fxck
Created January 13, 2015 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxck/d65255218de3611df3cd to your computer and use it in GitHub Desktop.
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 ...>
<?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