Add a basic inline stylesheet to Mobipocket books

This commit is contained in:
Marshall T. Vandegrift 2008-07-21 20:14:15 -04:00
parent 318de321f1
commit 70ac293e17

View File

@ -167,8 +167,14 @@ class MobiReader(object):
self.replace_page_breaks() self.replace_page_breaks()
self.cleanup_html() self.cleanup_html()
self.processed_html = re.compile('<head>', re.IGNORECASE).sub( self.processed_html = \
'<head>\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n', re.compile('<head>', re.IGNORECASE).sub(
'<head>\n'
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n'
'<style type="text/css">\n'
'blockquote { margin: 0em 0em 0em 1.25em; text-align: justify; }\n'
'p { margin: 0em; text-align: justify; }\n'
'</style>\n',
self.processed_html) self.processed_html)
soup = BeautifulSoup(self.processed_html.replace('> <', '>\n<')) soup = BeautifulSoup(self.processed_html.replace('> <', '>\n<'))
@ -214,6 +220,11 @@ class MobiReader(object):
del tag['width'] del tag['width']
except KeyError: except KeyError:
pass pass
try:
styles.append('text-align: %s' % tag['align'])
del tag['align']
except KeyError:
pass
if styles: if styles:
tag['style'] = '; '.join(styles) tag['style'] = '; '.join(styles)