diff --git a/Parsedown.php b/Parsedown.php index ae0cbdecd..5b91e35f2 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -81,6 +81,24 @@ function setUrlsLinked($urlsLinked) return $this; } + protected $strippedElements = array(); + + public function setStrippedImages($stripImages) + { + $pos = array_search('img', $this->strippedElements); + if ($stripImages) + { + if ($pos === false) + $this->strippedElements[] = 'img'; + } + else + { + if ($pos !== false) + array_splice($this->strippedElements, $pos, 1); + } + } + + protected $urlsLinked = true; function setSafeMode($safeMode) @@ -316,6 +334,11 @@ protected function linesElements(array $lines) return $Elements; } + protected function isElementStripped(array $Component) + { + return (isset($Component['element']['name']) && in_array($Component['element']['name'], $this->strippedElements)); + } + protected function extractElement(array $Component) { if ( ! isset($Component['element'])) @@ -1199,8 +1222,12 @@ protected function lineElements($text, $nonNestables = array()) $InlineText = $this->inlineText($unmarkedText); $Elements[] = $InlineText['element']; - # compile the inline - $Elements[] = $this->extractElement($Inline); + # make sure element is not stripped + if (!$this->isElementStripped($Inline)) + { + # compile the inline + $Elements[] = $this->extractElement($Inline); + } # remove the examined text $text = substr($text, $Inline['position'] + $Inline['extent']);