From c244fa5be5185a23addb98da68f937fd4be6f582 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 26 Apr 2012 10:45:59 -0400 Subject: Upon document generation, CData objects are no longer run through the formatter. [bug=988905] --- doc/source/index.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'doc/source') diff --git a/doc/source/index.rst b/doc/source/index.rst index 5b65354..17d2211 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -2048,7 +2048,6 @@ to Beautiful Soup generating invalid HTML/XML, as in these examples:: print(link_soup.a.encode(formatter=None)) # A link - Finally, if you pass in a function for ``formatter``, Beautiful Soup will call that function once for every string and attribute value in the document. You can do whatever you want in this function. Here's a @@ -2096,6 +2095,21 @@ whenever possible, but `also` converts all strings to uppercase:: # # +One last caveat: if you create a ``CData`` object, the text inside +that object is always presented `exactly as it appears, with no +formatting`. Beautiful Soup will call the formatter method, just in +case you've written a custom method that counts all the strings in the +document or something, but it will ignore the return value. + + from bs4.element import CData + soup = BeautifulSoup("") + soup.a.string = CData("one < three") + print(soup.a.prettify(formatter="xml")) + # + # + # + + ``get_text()`` -------------- -- cgit v1.2.3