mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Allow images to be stripped
This commit is contained in:
parent
cb17b6477d
commit
644862c6db
@ -73,6 +73,24 @@ class Parsedown
|
|||||||
return $this;
|
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;
|
protected $urlsLinked = true;
|
||||||
|
|
||||||
function setSafeMode($safeMode)
|
function setSafeMode($safeMode)
|
||||||
@ -1109,7 +1127,14 @@ class Parsedown
|
|||||||
$markup .= $this->unmarkedText($unmarkedText);
|
$markup .= $this->unmarkedText($unmarkedText);
|
||||||
|
|
||||||
# compile the inline
|
# compile the inline
|
||||||
$markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
|
if (isset($Inline['markup']))
|
||||||
|
$markup .= $Inline['markup'];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
# make sure element is not stripped
|
||||||
|
if (!$this->isElementStripped($Inline['element']))
|
||||||
|
$markup .= $this->element($Inline['element']);
|
||||||
|
}
|
||||||
|
|
||||||
# remove the examined text
|
# remove the examined text
|
||||||
$text = substr($text, $Inline['position'] + $Inline['extent']);
|
$text = substr($text, $Inline['position'] + $Inline['extent']);
|
||||||
@ -1467,6 +1492,11 @@ class Parsedown
|
|||||||
# Handlers
|
# Handlers
|
||||||
#
|
#
|
||||||
|
|
||||||
|
protected function isElementStripped(array $Element)
|
||||||
|
{
|
||||||
|
return (isset($Element['name']) && in_array($Element['name'], $this->strippedElements));
|
||||||
|
}
|
||||||
|
|
||||||
protected function element(array $Element)
|
protected function element(array $Element)
|
||||||
{
|
{
|
||||||
if ($this->safeMode)
|
if ($this->safeMode)
|
||||||
|
Loading…
Reference in New Issue
Block a user