summaryrefslogtreecommitdiff
path: root/bs4/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'bs4/__init__.py')
-rw-r--r--bs4/__init__.py20
1 files changed, 5 insertions, 15 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py
index cc4b27f..c78c54e 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -302,28 +302,18 @@ class BeautifulSoup(Tag):
def object_was_parsed(self, o, parent=None, most_recent_element=None):
"""Add an object to the parse tree."""
parent = parent or self.currentTag
- most_recent_element = most_recent_element or self._most_recent_element
+ previous_element = most_recent_element or self._most_recent_element
+ next_element = previous_sibling = next_sibling = None
if isinstance(o, Tag):
next_element = o.next_element
next_sibling = o.next_sibling
previous_sibling = o.previous_sibling
- previous_element = o.previous_element
+ if not previous_element:
+ previous_element = o.previous_element
- o.setup(parent, most_recent_element)
+ o.setup(parent, previous_element, next_element, previous_sibling, next_sibling)
- 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
parent.contents.append(o)