Fix #1349536 [convert do not preserve spaces in <pre>](https://bugs.launchpad.net/calibre/+bug/1349536)

This commit is contained in:
Kovid Goyal 2014-07-30 10:23:16 +05:30
parent a799191771
commit c89d454838

View File

@ -972,6 +972,7 @@ class BeautifulStoneSoup(Tag, SGMLParser):
NESTABLE_TAGS = {} NESTABLE_TAGS = {}
RESET_NESTING_TAGS = {} RESET_NESTING_TAGS = {}
QUOTE_TAGS = {} QUOTE_TAGS = {}
PRESERVE_WHITESPACE_TAGS = frozenset()
MARKUP_MASSAGE = [(re.compile('(<[^<>]*)/>'), MARKUP_MASSAGE = [(re.compile('(<[^<>]*)/>'),
lambda x: x.group(1) + ' />'), lambda x: x.group(1) + ' />'),
@ -1155,7 +1156,10 @@ class BeautifulStoneSoup(Tag, SGMLParser):
def endData(self, containerClass=NavigableString): def endData(self, containerClass=NavigableString):
if self.currentData: if self.currentData:
currentData = ''.join(self.currentData) currentData = ''.join(self.currentData)
if not currentData.translate(self.STRIP_ASCII_SPACES): # Changed by Kovid to not clobber whitespace inside <pre> tags and the like
if ( (not currentData.translate(self.STRIP_ASCII_SPACES)) and (
not frozenset(tag.name for tag in self.tagStack).intersection(
self.PRESERVE_WHITESPACE_TAGS))):
if '\n' in currentData: if '\n' in currentData:
currentData = '\n' currentData = '\n'
else: else:
@ -1443,6 +1447,8 @@ class BeautifulSoup(BeautifulStoneSoup):
['br' , 'hr', 'input', 'img', 'meta', ['br' , 'hr', 'input', 'img', 'meta',
'spacer', 'link', 'frame', 'base']) 'spacer', 'link', 'frame', 'base'])
PRESERVE_WHITESPACE_TAGS = frozenset(('pre', 'textarea'))
QUOTE_TAGS = {'script' : None, 'textarea' : None} QUOTE_TAGS = {'script' : None, 'textarea' : None}
#According to the HTML standard, each of these inline tags can #According to the HTML standard, each of these inline tags can