1
1
mirror of https://git.launchpad.net/beautifulsoup synced 2025-10-05 16:02:46 +02:00

Fixed a regression where HTMLFormatter and XMLFormatter were not

propagating the indent parameter to the superconstructor. [bug=2097272]
This commit is contained in:
Leonard Richardson
2025-02-03 07:09:27 -05:00
parent e61d81ca34
commit 30cd3b9c6b
5 changed files with 19 additions and 10 deletions

View File

@@ -5,6 +5,8 @@
[bug=2097262]
* Restored the English documentation to the source distribution.
[bug=2097237]
* Fixed a regression where HTMLFormatter and XMLFormatter were not
propagating the indent parameter to the superconstructor. [bug=2097272]
= 4.13.0 (20250202)

View File

@@ -192,17 +192,11 @@ class TreeBuilder(object):
doesn't keep track of this information, then store_line_numbers
is irrelevant.
:param attribute_dict_class: A Tag's attribute values (available
as tag.attrs) willl be stored in an instance of this class.
The default is Beautiful Soup's built-in `AttributeDict` class and
you will probably never need to change it.
:param attribute_dict_class: The value of a multi-valued attribute
(such as HTML's 'class') willl be stored in an instance of this
class. The default is Beautiful Soup's built-in
`AttributeValueList`, which is a normal Python list, and you
will probably never need to change it.
"""
USE_DEFAULT: Any = object() #: :meta private:

View File

@@ -83,7 +83,7 @@ class Formatter(EntitySubstitution):
void_element_close_prefix: str = "/",
cdata_containing_tags: Optional[Set[str]] = None,
empty_attributes_are_booleans: bool = False,
indent: int = 1,
indent: Union[int,str] = 1,
):
r"""Constructor.
@@ -201,7 +201,7 @@ class HTMLFormatter(Formatter):
void_element_close_prefix: str = "/",
cdata_containing_tags: Optional[Set[str]] = None,
empty_attributes_are_booleans: bool = False,
indent: int = 1,
indent: Union[int,str] = 1,
):
super(HTMLFormatter, self).__init__(
self.HTML,
@@ -209,6 +209,7 @@ class HTMLFormatter(Formatter):
void_element_close_prefix,
cdata_containing_tags,
empty_attributes_are_booleans,
indent=indent
)
@@ -223,7 +224,7 @@ class XMLFormatter(Formatter):
void_element_close_prefix: str = "/",
cdata_containing_tags: Optional[Set[str]] = None,
empty_attributes_are_booleans: bool = False,
indent: int = 1,
indent: Union[int,str] = 1,
):
super(XMLFormatter, self).__init__(
self.XML,
@@ -231,6 +232,7 @@ class XMLFormatter(Formatter):
void_element_close_prefix,
cdata_containing_tags,
empty_attributes_are_booleans,
indent=indent,
)

View File

@@ -109,6 +109,17 @@ class TestFormatter(SoupTest):
formatter = Formatter()
assert formatter.indent == " "
@pytest.mark.parametrize("formatter,expect",
[
(HTMLFormatter(indent=1), "<p>\n a\n</p>\n"),
(HTMLFormatter(indent=2), "<p>\n a\n</p>\n"),
(XMLFormatter(indent=1), "<p>\n a\n</p>\n"),
(XMLFormatter(indent="\t"), "<p>\n\ta\n</p>\n"),
] )
def test_indent_subclasses(self, formatter, expect):
soup = self.soup("<p>a</p>")
assert expect == soup.p.prettify(formatter=formatter)
@pytest.mark.parametrize(
"s,expect_html,expect_html5",
[

View File

@@ -15,7 +15,7 @@ deps = lxml
packaging
soupsieve>=2.6
pytest>=6
typing_extensions
typing_extensions>=4.0.0
commands = pytest {tty:--color=yes} {posargs}
[testenv:docs]