EPUB output:Map <br> tags that are childern of <body> to <p>&nbsp;</p> to get ADE to display them as line breaks.

This commit is contained in:
Kovid Goyal 2009-01-18 19:57:06 -08:00
parent 6b1d2571c1
commit e1c4e0bd45

View File

@ -129,6 +129,8 @@ class HTMLProcessor(Processor, Rationalizer):
for script in list(self.body.xpath('descendant::script')):
script.getparent().remove(script)
self.fix_markup()
def convert_image(self, img):
rpath = img.get('src', '')
path = os.path.join(os.path.dirname(self.save_path()), *rpath.split('/'))
@ -146,6 +148,17 @@ class HTMLProcessor(Processor, Rationalizer):
self.resource_map[key] = rpath+'_calibre_converted.jpg'
img.set('src', rpath+'_calibre_converted.jpg')
def fix_markup(self):
'''
Perform various markup transforms to get the output to render correctly
in the quirky ADE.
'''
# Replace <br> that are children of <body> with <p>&nbsp;</p>
if hasattr(self.body, 'xpath'):
for br in self.body.xpath('./br'):
br.tag = 'p'
br.text = u'\u00a0'
def save(self):
for meta in list(self.root.xpath('//meta')):
meta.getparent().remove(meta)