summaryrefslogtreecommitdiff
path: root/bs4/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/__init__.py')
-rw-r--r--bs4/__init__.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py
index 9f602ae..cc4b27f 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -303,8 +303,25 @@ class BeautifulSoup(Tag):
"""Add an object to the parse tree."""
parent = parent or self.currentTag
most_recent_element = most_recent_element or self._most_recent_element
+
+ if isinstance(o, Tag):
+ next_element = o.next_element
+ next_sibling = o.next_sibling
+ previous_sibling = o.previous_sibling
+ previous_element = o.previous_element
+
o.setup(parent, most_recent_element)
+ if isinstance(o, Tag):
+ if next_element:
+ o.next_element = next_element
+ if next_sibling:
+ o.next_sibling = next_sibling
+ if previous_sibling:
+ o.previous_sibling = previous_sibling
+ if previous_element:
+ o.previous_element = previous_element
+
if most_recent_element is not None:
most_recent_element.next_element = o
self._most_recent_element = o