diff options
Diffstat (limited to 'beautifulsoup/element.py')
-rw-r--r-- | beautifulsoup/element.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/beautifulsoup/element.py b/beautifulsoup/element.py index 5793d59..c0c28d4 100644 --- a/beautifulsoup/element.py +++ b/beautifulsoup/element.py @@ -429,7 +429,6 @@ class Tag(PageElement, Entities): # chunks be garbage-collected. self.parserClass = parser.__class__ self.name = name - self.isSelfClosing = builder.isSelfClosingTag(name) if attrs == None: attrs = [] if isinstance(attrs, types.DictType): @@ -447,6 +446,26 @@ class Tag(PageElement, Entities): # Set up any substitutions, such as the charset in a META tag. self.contains_substitutions = builder.set_up_substitutions(self) + self.can_be_empty_element = (builder.can_be_empty_element(name)) + + @property + def is_empty_element(self): + """Is this tag an empty-element tag? (aka a self-closing tag) + + A tag that has contents is never an empty-element tag. + + A tag that has no contents may or may not be an empty-element + tag. It depends on the builder used to create the tag. If the + builder has a designated list of empty-element tags, then only + a tag whose name shows up in that list is considered an + empty-element tag. + + If the builder has no designated list of empty-element tags, + then any tag with no contents is an empty-element tag. + """ + return len(self.contents) == 0 and self.can_be_empty_element + isSelfClosing = is_empty_element # BS3 + @property def string(self): @@ -624,7 +643,7 @@ class Tag(PageElement, Entities): attrs.append(decoded) close = '' closeTag = '' - if self.isSelfClosing: + if self.is_empty_element: close = ' /' else: closeTag = '</%s>' % self.name |