summaryrefslogtreecommitdiff
path: root/src/Readability.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Readability.php')
-rw-r--r--src/Readability.php10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Readability.php b/src/Readability.php
index 027858f..c55e0ad 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -286,8 +286,9 @@ class Readability extends Element implements ReadabilityInterface
* element with the new tag name and importing it to the main DOMDocument.
*
* @param string $value
+ * @param bool $importAttributes
*/
- public function setNodeTag($value)
+ public function setNodeTag($value, $importAttributes = false)
{
$new = new \DOMDocument();
$new->appendChild($new->createElement($value));
@@ -298,6 +299,13 @@ class Readability extends Element implements ReadabilityInterface
$new->firstChild->appendChild($import);
}
+ if ($importAttributes) {
+ // Import attributes from the original node.
+ foreach ($this->node->attributes as $attribute) {
+ $new->firstChild->setAttribute($attribute->nodeName, $attribute->nodeValue);
+ }
+ }
+
// The import must be done on the firstChild of $new, since $new is a DOMDocument and not a DOMElement.
$import = $this->node->ownerDocument->importNode($new->firstChild, true);
$this->node->parentNode->replaceChild($import, $this->node);