diff options
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/bs4/element.py b/bs4/element.py index 547b8ba..1183f77 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -861,12 +861,27 @@ class Tag(PageElement): self.setup(parent, previous) self.hidden = False - # Set up any substitutions, such as the charset in a META tag. - if builder is not None: + if builder is None: + # In the absence of a TreeBuilder, assume this tag is nothing + # special. + self.can_be_empty_element = False + self.cdata_list_attributes = None + else: + # Set up any substitutions for this tag, such as the charset in a META tag. builder.set_up_substitutions(self) + + # Ask the TreeBuilder whether this tag might be an empty-element tag. self.can_be_empty_element = builder.can_be_empty_element(name) - else: - self.can_be_empty_element = False + + # Keep track of the list of attributes of this tag that + # might need to be treated as a list. + # + # For performance reasons, we store the whole data structure + # rather than asking the question of every tag. Asking would + # require building a new data structure every time, and + # (unlike can_be_empty_element), we almost never need + # to check this. + self.cdata_list_attributes = builder.cdata_list_attributes parserClass = _alias("parser_class") # BS3 |