mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ODT Input: Add support for numbered lists that do not start numbering at 1. Fixes #1475846 [ordered list numbering is off if starts at not-1](https://bugs.launchpad.net/calibre/+bug/1475846)
This commit is contained in:
parent
8e33b0503e
commit
1d717ccaec
@ -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%'
|
||||
|
@ -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] = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user