summaryrefslogtreecommitdiff
path: root/bs4/element.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2016-07-16 12:21:15 -0400
committerLeonard Richardson <leonardr@segfault.org>2016-07-16 12:21:15 -0400
commit682233e4c9e9fa11b5b84055e0bb272f5e941194 (patch)
tree67eed54264943be78b4a115922bae09453f61be2 /bs4/element.py
parentadcfa8e5ec199c41f5b22041dbfeb852aa034434 (diff)
The contents of <textarea> tags will no longer be modified when the
tree is prettified. [bug=1555829]
Diffstat (limited to 'bs4/element.py')
-rw-r--r--bs4/element.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/bs4/element.py b/bs4/element.py
index 9e2bfec..955f0fc 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -101,6 +101,8 @@ class HTMLAwareEntitySubstitution(EntitySubstitution):
preformatted_tags = set(["pre"])
+ preserve_whitespace_tags = set(['pre', 'textarea'])
+
@classmethod
def _substitute_if_appropriate(cls, ns, f):
if (isinstance(ns, NavigableString)
@@ -1065,10 +1067,18 @@ class Tag(PageElement):
def _should_pretty_print(self, indent_level):
"""Should this tag be pretty-printed?"""
+ if self.builder:
+ preserve_whitespace_tags = self.builder.preserve_whitespace_tags
+ else:
+ if self._is_xml:
+ preserve_whitespace_tags = []
+ else:
+ preserve_whitespace_tags = HTMLAwareEntitySubstitution.preserve_whitespace_tags
+
return (
- indent_level is not None and
- (self.name not in HTMLAwareEntitySubstitution.preformatted_tags
- or self._is_xml))
+ indent_level is not None
+ and self.name not in preserve_whitespace_tags
+ )
def decode(self, indent_level=None,
eventual_encoding=DEFAULT_OUTPUT_ENCODING,