summaryrefslogtreecommitdiff
path: root/vendor/league/commonmark/src/Node/Node.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/league/commonmark/src/Node/Node.php')
-rw-r--r--vendor/league/commonmark/src/Node/Node.php21
1 files changed, 21 insertions, 0 deletions
diff --git a/vendor/league/commonmark/src/Node/Node.php b/vendor/league/commonmark/src/Node/Node.php
index 07b0f75018..96644b7cdc 100644
--- a/vendor/league/commonmark/src/Node/Node.php
+++ b/vendor/league/commonmark/src/Node/Node.php
@@ -255,4 +255,25 @@ abstract class Node
{
return new NodeWalker($this);
}
+
+ /**
+ * Clone the current node and its children
+ *
+ * WARNING: This is a recursive function and should not be called on deeply-nested node trees!
+ */
+ public function __clone()
+ {
+ // Cloned nodes are detached from their parents, siblings, and children
+ $this->parent = null;
+ $this->previous = null;
+ $this->next = null;
+ // But save a copy of the children since we'll need that in a moment
+ $children = $this->children();
+ $this->detachChildren();
+
+ // The original children get cloned and re-added
+ foreach ($children as $child) {
+ $this->appendChild(clone $child);
+ }
+ }
}