[parsing] unify tag nesting

This commit is contained in:
Marcel 2022-11-30 17:21:09 +01:00
parent 65f91148fc
commit 8d87bb4d91
No known key found for this signature in database
GPG Key ID: 7813C97693AD6AAE
2 changed files with 5 additions and 6 deletions

View File

@ -325,9 +325,9 @@ def test_tag_return_order(self):
str(tags), str([
[Tag('t0'),
[Tag('t1'),
[Tag('t2'), Tag('t3'), Tag('t4')]],
[Tag('t5'), Tag('t6')]],
[Tag('t7'), Tag('t8')]]))
[Tag('t2'), [Tag('t3')], [Tag('t4')]]],
[Tag('t5'), [Tag('t6')]]],
[Tag('t7'), [Tag('t8')]]]))
def test_html_ignored_ranges(self):
def mark_comments(_string, char='^', nochar='-'):

View File

@ -174,12 +174,11 @@ def handle_starttag(self, tag, attrs):
if self.predicate(tag, attrs):
tag_obj = self.Tag(tag, string=self.rawdata, attrs=attrs)
tag_obj.openrange(self._offset, len(tag_text))
nesting = [tag_obj]
self._nestedtags[-1].append(nesting)
if tag_is_open:
nesting = [tag_obj]
self._nestedtags[-1].append(nesting)
self._nestedtags.append(nesting)
else:
self._nestedtags[-1].append(tag_obj)
self.callback(tag_obj)
if tag_is_open:
self.tagstack.appendleft(tag_obj)