From c84e08aa77764578ca1be2a322a4a7bed12d6851 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 24 May 2012 08:14:37 -0400 Subject: Comments, processing instructions, document type declarations, and markup declarations are now treated as preformatted strings, the way CData blocks are. [bug=1001025] Also in this commit: renamed detwingle method to detwingle(). --- bs4/element.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'bs4/element.py') diff --git a/bs4/element.py b/bs4/element.py index 3ef6ef1..22b8304 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -678,10 +678,12 @@ class NavigableString(unicode, PageElement): return self.PREFIX + output + self.SUFFIX -class CData(NavigableString): +class PreformattedString(NavigableString): + """A NavigableString not subject to the normal formatting rules. - PREFIX = u'' + The string will be passed into the formatter (to trigger side effects), + but the return value will be ignored. + """ def output_ready(self, formatter="minimal"): """CData strings are passed into the formatter. @@ -689,25 +691,28 @@ class CData(NavigableString): self.format_string(self, formatter) return self.PREFIX + self + self.SUFFIX +class CData(PreformattedString): -class ProcessingInstruction(NavigableString): + PREFIX = u'' + +class ProcessingInstruction(PreformattedString): PREFIX = u'' - -class Comment(NavigableString): +class Comment(PreformattedString): PREFIX = u'' -class Declaration(NavigableString): +class Declaration(PreformattedString): PREFIX = u'' -class Doctype(NavigableString): +class Doctype(PreformattedString): @classmethod def for_name_and_ids(cls, name, pub_id, system_id): -- cgit v1.2.3