mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DOCX Input: Change handling of sequences of space characters to more closely follow Microsoft Word.
This commit is contained in:
parent
28e6946de4
commit
4618304369
@ -581,17 +581,21 @@ class Convert(object):
|
|||||||
continue
|
continue
|
||||||
space = child.get(XML('space'), None)
|
space = child.get(XML('space'), None)
|
||||||
preserve = False
|
preserve = False
|
||||||
if space == 'preserve':
|
ctext = child.text
|
||||||
|
if space != 'preserve':
|
||||||
|
# Remove leading and trailing whitespace. Word ignores
|
||||||
|
# leading and trailing whitespace without preserve
|
||||||
|
ctext = ctext.strip()
|
||||||
# Only use a <span> with white-space:pre-wrap if this element
|
# Only use a <span> with white-space:pre-wrap if this element
|
||||||
# actually needs it, i.e. if it has more than one
|
# actually needs it, i.e. if it has more than one
|
||||||
# consecutive space or it has newlines or tabs.
|
# consecutive space or it has newlines or tabs.
|
||||||
multi_spaces = self.ms_pat.search(child.text) is not None
|
multi_spaces = self.ms_pat.search(ctext) is not None
|
||||||
preserve = multi_spaces or self.ws_pat.search(child.text) is not None
|
preserve = multi_spaces or self.ws_pat.search(ctext) is not None
|
||||||
if preserve:
|
if preserve:
|
||||||
text.add_elem(SPAN(child.text, style="white-space:pre-wrap"))
|
text.add_elem(SPAN(ctext, style="white-space:pre-wrap"))
|
||||||
ans.append(text.elem)
|
ans.append(text.elem)
|
||||||
else:
|
else:
|
||||||
text.buf.append(child.text)
|
text.buf.append(ctext)
|
||||||
elif is_tag(child, 'w:cr'):
|
elif is_tag(child, 'w:cr'):
|
||||||
text.add_elem(BR())
|
text.add_elem(BR())
|
||||||
ans.append(text.elem)
|
ans.append(text.elem)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user