diff --git a/src/Html/Renderables/Container.php b/src/Html/Renderables/Container.php
index 9192afb..ce52933 100644
--- a/src/Html/Renderables/Container.php
+++ b/src/Html/Renderables/Container.php
@@ -3,8 +3,9 @@
namespace Erusev\Parsedown\Html\Renderables;
use Erusev\Parsedown\Html\Renderable;
+use Erusev\Parsedown\Html\TransformableRenderable;
-final class Container implements Renderable
+final class Container implements TransformableRenderable
{
use CanonicalStateRenderable;
@@ -44,4 +45,22 @@ final class Container implements Renderable
''
);
}
+
+ /**
+ * @param \Closure(string):Renderable $Transform
+ * @return Renderable
+ */
+ public function transformingContent(\Closure $Transform): Renderable
+ {
+ return new Container(\array_map(
+ function (Renderable $R) use ($Transform): Renderable {
+ if (! $R instanceof TransformableRenderable) {
+ return $R;
+ }
+
+ return $R->transformingContent($Transform);
+ },
+ $this->Contents
+ ));
+ }
}
diff --git a/src/Html/Renderables/Element.php b/src/Html/Renderables/Element.php
index 14ef739..3a41df6 100644
--- a/src/Html/Renderables/Element.php
+++ b/src/Html/Renderables/Element.php
@@ -5,8 +5,9 @@ namespace Erusev\Parsedown\Html\Renderables;
use Erusev\Parsedown\Html\Renderable;
use Erusev\Parsedown\Html\Sanitisation\CharacterFilter;
use Erusev\Parsedown\Html\Sanitisation\Escaper;
+use Erusev\Parsedown\Html\TransformableRenderable;
-final class Element implements Renderable
+final class Element implements TransformableRenderable
{
use CanonicalStateRenderable;
@@ -191,4 +192,26 @@ final class Element implements Renderable
return $html;
}
+
+ /**
+ * @param \Closure(string):Renderable $Transform
+ * @return Renderable
+ */
+ public function transformingContent(\Closure $Transform): Renderable
+ {
+ if (! isset($this->Contents)) {
+ return $this;
+ }
+
+ return new self($this->name, $this->attributes, \array_map(
+ function (Renderable $R) use ($Transform): Renderable {
+ if (! $R instanceof TransformableRenderable) {
+ return $R;
+ }
+
+ return $R->transformingContent($Transform);
+ },
+ $this->Contents
+ ));
+ }
}
diff --git a/src/Html/Renderables/Text.php b/src/Html/Renderables/Text.php
index 7c100f7..54fb4d1 100644
--- a/src/Html/Renderables/Text.php
+++ b/src/Html/Renderables/Text.php
@@ -4,8 +4,9 @@ namespace Erusev\Parsedown\Html\Renderables;
use Erusev\Parsedown\Html\Renderable;
use Erusev\Parsedown\Html\Sanitisation\Escaper;
+use Erusev\Parsedown\Html\TransformableRenderable;
-final class Text implements Renderable
+final class Text implements TransformableRenderable
{
use CanonicalStateRenderable;
@@ -31,4 +32,13 @@ final class Text implements Renderable
{
return Escaper::htmlElementValueEscapingDoubleQuotes($this->text);
}
+
+ /**
+ * @param \Closure(string):Renderable $Transform
+ * @return Renderable
+ */
+ public function transformingContent(\Closure $Transform): Renderable
+ {
+ return $Transform($this->text);
+ }
}
diff --git a/src/Html/TransformableRenderable.php b/src/Html/TransformableRenderable.php
new file mode 100644
index 0000000..9497dcb
--- /dev/null
+++ b/src/Html/TransformableRenderable.php
@@ -0,0 +1,25 @@
+