Skip to content

Instantly share code, notes, and snippets.

@apfelbox
Last active August 12, 2016 09:59
Show Gist options
  • Save apfelbox/f6bfcf7fe14ebb5d5171 to your computer and use it in GitHub Desktop.
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 ...>
<?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);
}
}
@apfelbox
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment