diff --git a/src/calibre/ebooks/odt/input.py b/src/calibre/ebooks/odt/input.py index b66f766e6d..0578518fa0 100644 --- a/src/calibre/ebooks/odt/input.py +++ b/src/calibre/ebooks/odt/input.py @@ -31,11 +31,23 @@ class Extract(ODF2XHTML): with open(name, 'wb') as f: f.write(data) + def apply_list_starts(self, root, log): + if not self.list_starts: + return + list_starts = frozenset(self.list_starts) + for ol in root.xpath('//*[local-name() = "ol" and @class]'): + classes = {'.' + x for x in ol.get('class', '').split()} + found = classes & list_starts + if found: + val = self.list_starts[next(iter(found))] + ol.set('start', val) + def fix_markup(self, html, log): root = etree.fromstring(html) self.filter_css(root, log) self.extract_css(root, log) self.epubify_markup(root, log) + self.apply_list_starts(root, log) html = etree.tostring(root, encoding='utf-8', xml_declaration=True) return html @@ -95,8 +107,7 @@ class Extract(ODF2XHTML): style = div.attrib.get('style', '') if style and not style.endswith(';'): style = style + ';' - style += 'position:static' # Ensures position of containing - # div is static + style += 'position:static' # Ensures position of containing div is static # Ensure that the img is always contained in its frame div.attrib['style'] = style img.attrib['style'] = 'max-width: 100%; max-height: 100%' diff --git a/src/odf/odf2xhtml.py b/src/odf/odf2xhtml.py index 17c8ac021e..b3f40231bc 100644 --- a/src/odf/odf2xhtml.py +++ b/src/odf/odf2xhtml.py @@ -511,6 +511,7 @@ class ODF2XHTML(handler.ContentHandler): self.stylestack = [] self.styledict = {} self.currentstyle = None + self.list_starts = {} self._resetfootnotes() @@ -1355,10 +1356,13 @@ dl.notes dd:last-of-type { page-break-after: avoid } def s_text_list_level_style_number(self, tag, attrs): name = self.tagstack.stackparent()[(STYLENS,'name')] level = attrs[(TEXTNS,'level')] - num_format = attrs.get((STYLENS,'name'),"1") + num_format = attrs.get((STYLENS,'num-format'),"1") + start_value = attrs.get((TEXTNS, 'start-value'), '1') list_class = "%s_%s" % (name, level) self.prevstyle = self.currentstyle self.currentstyle = ".%s_%s" % (name.replace(".","_"), level) + if start_value != '1': + self.list_starts[self.currentstyle] = start_value self.listtypes[list_class] = 'ol' self.stylestack.append(self.currentstyle) self.styledict[self.currentstyle] = {}