MOBI Input: Assume unit less numbers are in pixels

This commit is contained in:
Kovid Goyal 2009-07-07 14:20:21 -06:00
parent a625a9f6ea
commit d850f6e2d6
2 changed files with 10 additions and 5 deletions

View File

@ -439,7 +439,12 @@ class MobiReader(object):
self.processed_html = '<html><p>' + self.processed_html.replace('\n\n', '<p>') + '</html>' self.processed_html = '<html><p>' + self.processed_html.replace('\n\n', '<p>') + '</html>'
self.processed_html = self.processed_html.replace('\r\n', '\n') self.processed_html = self.processed_html.replace('\r\n', '\n')
self.processed_html = self.processed_html.replace('> <', '>\n<') self.processed_html = self.processed_html.replace('> <', '>\n<')
self.processed_html = re.sub('\x14|\x15', '', self.processed_html) self.processed_html = re.sub('\x14|\x15|\x1c|\x1d', '', self.processed_html)
def ensure_unit(self, raw, unit='px'):
if re.search(r'\d+$', raw) is not None:
raw += unit
return raw
def upshift_markup(self, root): def upshift_markup(self, root):
self.log.debug('Converting style information to CSS...') self.log.debug('Converting style information to CSS...')
@ -469,13 +474,13 @@ class MobiReader(object):
if attrib.has_key('height'): if attrib.has_key('height'):
height = attrib.pop('height').strip() height = attrib.pop('height').strip()
if height: if height:
styles.append('margin-top: %s' % height) styles.append('margin-top: %s' % self.ensure_unit(height))
if attrib.has_key('width'): if attrib.has_key('width'):
width = attrib.pop('width').strip() width = attrib.pop('width').strip()
if width: if width:
styles.append('text-indent: %s' % width) styles.append('text-indent: %s' % self.ensure_unit(width))
if width.startswith('-'): if width.startswith('-'):
styles.append('margin-left: %s' % (width[1:])) styles.append('margin-left: %s' % self.ensure_unit(width[1:]))
if attrib.has_key('align'): if attrib.has_key('align'):
align = attrib.pop('align').strip() align = attrib.pop('align').strip()
if align: if align:

View File

@ -34,7 +34,7 @@ class Clean(object):
for x in list(self.oeb.guide): for x in list(self.oeb.guide):
href = urldefrag(self.oeb.guide[x].href)[0] href = urldefrag(self.oeb.guide[x].href)[0]
if x.lower() not in ('cover', 'titlepage'): if x.lower() not in ('cover', 'titlepage', 'masthead'):
self.oeb.guide.remove(x) self.oeb.guide.remove(x)