diff options
author | Leonard Richardson <leonardr@segfault.org> | 2018-07-15 19:50:15 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2018-07-15 19:50:15 -0400 |
commit | 999a1ad671036ccbb4704d402dff624083fbee90 (patch) | |
tree | dbbedfcbb0590ccab3098f52c0c5f6ec25991d25 /doc/source/index.rst | |
parent | db0ef1662efba41a111861d652a248385f7baac9 (diff) | |
download | beautifulsoup4-999a1ad671036ccbb4704d402dff624083fbee90.tar.gz |
Introduced the Formatter system. [bug=1716272].
Diffstat (limited to 'doc/source/index.rst')
-rw-r--r-- | doc/source/index.rst | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/doc/source/index.rst b/doc/source/index.rst index e1b73aa..cc816a0 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -2145,7 +2145,7 @@ invalid HTML or XML:: You can change this behavior by providing a value for the ``formatter`` argument to ``prettify()``, ``encode()``, or -``decode()``. Beautiful Soup recognizes four possible values for +``decode()``. Beautiful Soup recognizes six possible values for ``formatter``. The default is ``formatter="minimal"``. Strings will only be processed @@ -2174,6 +2174,18 @@ Unicode characters to HTML entities whenever possible:: # </body> # </html> + If you pass in ``formatter="html5"``, it's the same as +``formatter="html5"``, but Beautiful Soup will +omit the closing slash in HTML void tags like "br":: + + soup = BeautifulSoup("<br>") + + print(soup.encode(formatter="html")) + # <html><body><br/></body></html> + + print(soup.encode(formatter="html5")) + # <html><body><br></body></html> + If you pass in ``formatter=None``, Beautiful Soup will not modify strings at all on output. This is the fastest option, but it may lead to Beautiful Soup generating invalid HTML/XML, as in these examples:: |