From 55c7eb963d3784e6e6c5e470a5947bb4e3afb756 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 14 May 2013 21:42:17 +0530 Subject: [PATCH] Fix lists implementad as tables having too large a left margin --- src/calibre/ebooks/docx/numbering.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/docx/numbering.py b/src/calibre/ebooks/docx/numbering.py index 8693e2a9a1..8a177ae40a 100644 --- a/src/calibre/ebooks/docx/numbering.py +++ b/src/calibre/ebooks/docx/numbering.py @@ -274,6 +274,11 @@ class Numbering(object): for wrap in body.xpath('//ol[@lvlid]'): wrap.attrib.pop('lvlid') wrap.tag = 'div' + text = '' + for li in wrap.iterchildren('li'): + t = li[0].text + if t and len(t) > len(text): + text = t for i, li in enumerate(wrap.iterchildren('li')): li.tag = 'div' li.attrib.pop('value', None) @@ -281,7 +286,8 @@ class Numbering(object): obj = object_map[li] bs = styles.para_cache[obj] if i == 0: - wrap.set('style', 'display:table; margin-left: %s' % (bs.css.get('margin-left', 0))) + m = len(text)//2 # Move the table left to simulate the behavior of a list (number is to the left of text margin) + wrap.set('style', 'display:table; margin-left: -%dem; padding-left: %s' % (m, bs.css.get('margin-left', 0))) bs.css.pop('margin-left', None) for child in li: child.set('style', 'display:table-cell')