From de4cddf85374ddfd90170e30eaa946c76bb5d3d1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 23 Sep 2013 13:13:18 +0530 Subject: [PATCH] DOCX Input: Convert tabs for indentation into indentation DOCX Input: Detect if tabs are used for paragraph indentation and convert those into proper indentation. --- src/calibre/ebooks/docx/to_html.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index e983e541e9..fa414b9503 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -132,6 +132,28 @@ class Convert(object): dl[-1].append(p) paras.append(wp) self.styles.apply_contextual_spacing(paras) + + for p, wp in self.object_map.iteritems(): + if len(p) > 0 and not p.text and len(p[0]) > 0 and not p[0].text and p[0][0].get('class', None) == 'tab': + # Paragraph uses tabs for indentation, convert to text-indent + parent = p[0] + tabs = [] + for child in parent: + if child.get('class', None) == 'tab': + tabs.append(child) + if child.tail: + break + else: + break + indent = len(tabs) * self.settings.default_tab_stop + style = self.styles.resolve(wp) + if style.text_indent is inherit or (hasattr(style.text_indent, 'endswith') and style.text_indent.endswith('pt')): + if style.text_indent is not inherit: + indent = float(style.text_indent[:-2]) + indent + style.text_indent = '%.3gpt' % indent + parent.text = tabs[-1].tail or '' + map(parent.remove, tabs) + self.images.rid_map = orig_rid_map self.resolve_links(relationships_by_id)