1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Transformations must return transformable renderables

This commit is contained in:
Aidan Woods 2021-10-13 19:46:53 +01:00
parent 05a47e7083
commit 7b0a9cda04
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
4 changed files with 17 additions and 18 deletions

View File

@ -51,10 +51,10 @@ final class Container implements TransformableRenderable
} }
/** /**
* @param \Closure(string):Renderable $Transform * @param \Closure(string):TransformableRenderable $Transform
* @return Renderable * @return TransformableRenderable
*/ */
public function transformingContent(\Closure $Transform): Renderable public function transformingContent(\Closure $Transform): TransformableRenderable
{ {
return new Container(\array_map( return new Container(\array_map(
function (Renderable $R) use ($Transform): Renderable { function (Renderable $R) use ($Transform): Renderable {
@ -68,7 +68,7 @@ final class Container implements TransformableRenderable
)); ));
} }
public function replacingAll(string $search, Renderable $Replacement): Renderable public function replacingAll(string $search, TransformableRenderable $Replacement): TransformableRenderable
{ {
return new Container(\array_map( return new Container(\array_map(
function (Renderable $R) use ($search, $Replacement): Renderable { function (Renderable $R) use ($search, $Replacement): Renderable {

View File

@ -194,10 +194,10 @@ final class Element implements TransformableRenderable
} }
/** /**
* @param \Closure(string):Renderable $Transform * @param \Closure(string):TransformableRenderable $Transform
* @return Renderable * @return TransformableRenderable
*/ */
public function transformingContent(\Closure $Transform): Renderable public function transformingContent(\Closure $Transform): TransformableRenderable
{ {
if (! isset($this->Contents)) { if (! isset($this->Contents)) {
return $this; return $this;
@ -215,7 +215,7 @@ final class Element implements TransformableRenderable
)); ));
} }
public function replacingAll(string $search, Renderable $Replacement): Renderable public function replacingAll(string $search, TransformableRenderable $Replacement): TransformableRenderable
{ {
if (! isset($this->Contents)) { if (! isset($this->Contents)) {
return $this; return $this;

View File

@ -2,7 +2,6 @@
namespace Erusev\Parsedown\Html\Renderables; namespace Erusev\Parsedown\Html\Renderables;
use Erusev\Parsedown\Html\Renderable;
use Erusev\Parsedown\Html\Sanitisation\Escaper; use Erusev\Parsedown\Html\Sanitisation\Escaper;
use Erusev\Parsedown\Html\TransformableRenderable; use Erusev\Parsedown\Html\TransformableRenderable;
@ -34,15 +33,15 @@ final class Text implements TransformableRenderable
} }
/** /**
* @param \Closure(string):Renderable $Transform * @param \Closure(string):TransformableRenderable $Transform
* @return Renderable * @return TransformableRenderable
*/ */
public function transformingContent(\Closure $Transform): Renderable public function transformingContent(\Closure $Transform): TransformableRenderable
{ {
return $Transform($this->text); return $Transform($this->text);
} }
public function replacingAll(string $search, Renderable $Replacement): Renderable public function replacingAll(string $search, TransformableRenderable $Replacement): TransformableRenderable
{ {
$searchLen = \strlen($search); $searchLen = \strlen($search);

View File

@ -18,17 +18,17 @@ interface TransformableRenderable extends Renderable
* *
* It is acceptable to only partially transform "contained text". * It is acceptable to only partially transform "contained text".
* *
* @param \Closure(string):Renderable $Transform * @param \Closure(string):TransformableRenderable $Transform
* @return Renderable * @return TransformableRenderable
*/ */
public function transformingContent(\Closure $Transform): Renderable; public function transformingContent(\Closure $Transform): TransformableRenderable;
/** /**
* Similar to transformingContent, but replace the string $search in text content * Similar to transformingContent, but replace the string $search in text content
* with the renderable $Replacement and return the result. * with the renderable $Replacement and return the result.
* *
* @param string $search * @param string $search
* @return Renderable * @return TransformableRenderable
*/ */
public function replacingAll(string $search, Renderable $Replacement): Renderable; public function replacingAll(string $search, TransformableRenderable $Replacement): TransformableRenderable;
} }